loadui.h
- #ifndef LOADUI_H
- #define LOADUI_H
- #include <QtGui/QDialog>
- #include "ui_loadui.h"
- class loadUi : public QDialog
- {
- Q_OBJECT
- public:
- loadUi(QWidget *parent = 0, Qt::WFlags flags = 0);
- ~loadUi();
- private:
- Ui::loadUiClass ui;
- private slots:
- void sl_creatChild();
- };
- #endif // LOADUI_H
loadui.cpp
- #include "loadui.h"
- #include <QtUiTools/QtUiTools>
- loadUi::loadUi(QWidget *parent, Qt::WFlags flags)
- : QDialog(parent, flags)
- {
- ui.setupUi(this);
- connect(ui.btnCreatChild,SIGNAL(clicked()),this,SLOT(sl_creatChild()));
- }
- loadUi::~loadUi()
- {
- }
- void loadUi::sl_creatChild()
- {
- QUiLoader loader;
- QFile file("forms/child.ui");
- file.open(QFile::ReadOnly);
- QWidget *widget_child = loader.load(&file);
- file.close();
- widget_child->show();
- }
main.cpp
- #include "loadui.h"
- #include <QtGui/QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- loadUi w;
- w.show();
- return a.exec();
- }
,还有资源里应该加载child.ui的路径。(<qresource><file>forms/child.ui</file></qresource>)