ui文件實際上是標(biāo)準(zhǔn)的xml格式的文本文件,它需要通過UIC工具轉(zhuǎn)換為項目中可用的文件,這是頭文件中可用的真正C++代碼,那么Qt之ui在程序中的使用-多繼承法介紹大家清楚嗎?別著急,武林技術(shù)頻道為大家細(xì)細(xì)道來。
#ifndef THIRDDIALOG_H
#define THIRDDIALOG_H
#include <QtGui>
#include "ui_third.h"
class thirdDialog:public QDialog,private Ui::Third
{
Q_OBJECT
public:
thirdDialog(QWidget *parent=0);
~thirdDialog();
};
#endif
thirdDialog.cpp
#include "thirdDialog.h"
thirdDialog::thirdDialog(QWidget *parent)
{
setupUi(this);
}
thirdDialog::~thirdDialog()
{
}
maindialog.h
?
?
?
#ifndef MAINDIALOG_H
#define MAINDIALOG_H
#include <QtGui>
#include "ui_first.h"
#include "ui_second.h"
#include "thirdDialog.h"
class MainDialog : public QDialog
{
Q_OBJECT
public:
MainDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
~MainDialog();
private:
Ui::First firstUi;
Ui::Second secondUi;
private slots:
void on_btnChild_clicked();
};
#endif // MAINDIALOG_H
maindialog.cpp
?
?
?
#include "maindialog.h"
MainDialog::MainDialog(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
QTabWidget *tabWidget = new QTabWidget(this);
QDialog *w1 = new QDialog;
firstUi.setupUi(w1);
QWidget *w2 = new QWidget;
secondUi.setupUi(w2);
tabWidget->addTab(w1,tr("First Tab"));
tabWidget->addTab(w2,tr("Second Tab"));
tabWidget->resize(300,300);
connect(firstUi.btnClose,SIGNAL(clicked()),this,SLOT(close()));
connect(secondUi.btnChild,SIGNAL(clicked()),this,SLOT(on_btnChild_clicked()));
}
MainDialog::~MainDialog()
{
}
void MainDialog::on_btnChild_clicked()
{
thirdDialog *dlg = new thirdDialog;
dlg->exec();
}
以上就是Qt之ui在程序中的使用-多繼承法介紹,不過一般都會先測試能否正常使用,不過大家還是可以放心的,更多的專業(yè)知識請關(guān)注武林技術(shù)頻道!