Qt版本:5.12.12
1.添加【模块】
Base class:可以选择QDialog、QWidget、QMainWindow
会自动生成MyDialog.h和MyDialog.cpp文件以及MyDialog.ui文件,
2.添加代码:
(1)TestDialog.h
#pragma once#include <QtWidgets/QMainWindow>
#include "ui_TestDialog.h"#include "MyDialog.h"class TestDialog : public QMainWindow
{Q_OBJECTpublic:TestDialog(QWidget *parent = nullptr);~TestDialog();MyDialog dlg;
public slots:void OpenDialog();private:Ui::TestDialogClass ui;
};
(2)TestDialog.cpp
#include "TestDialog.h"TestDialog::TestDialog(QWidget *parent): QMainWindow(parent)
{ui.setupUi(this);//连接信号和槽connect(ui.pushButton_Open, SIGNAL(clicked()), this, SLOT(OpenDialog()));
}TestDialog::~TestDialog()
{}void TestDialog::OpenDialog()
{dlg.show();
}