你的代码已经表明了父子关系,按道理不应该出现你说的情况!我做了个简单的测试,测试代码如下:
/////////////main.cpp:
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
int result = 0;
QApplication a(argc, argv);
test w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
result = a.exec();
return result;
}
///////////////test.h:
#ifndef TEST_H
#define TEST_H
#include <QMainWindow>
#include "ui_test.h"
#include "newdialog.h"
class test : public QMainWindow
{
Q_OBJECT
public:
test(QWidget *parent = 0);
~test();
private slots:
void NewDlg();
private:
Ui::test ui;
NewDialog*uinew;
};
#endif // TEST_H
//////////////////////test.cpp
#include "test.h"
test::test(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(NewDlg()));
}
test::~test()
{
}
void test::NewDlg()
{
uinew = new NewDialog(this);
uinew->show();
}