标题:请问关于窗口间的父子关系的问题
作者:kytexzy
日期:2006-11-09 16:35
内容:
我的一个窗口A中有一个按钮,当我点击按钮时,会弹出一个新的对话框,按理来说这个对话框应该是原来窗口A的孩子,可是当我关闭窗口A时这个对话框却没有关闭,请问我怎么用代码表示这种父子关系?
对话框的构造函数如下:
TypeSet::TypeSet(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
打开对话框的函数如下:
void WorkRecord::typeSet()
{
TypeSet *typeSet = new TypeSet(this);
typeSet->show();
}
#1 [kytexzy 11-10 11:16]
请问我怎样才能在我关闭父窗口时把子窗口也关闭?
#2 [penguinfish 11-13 15:12]
你的代码已经表明了父子关系,按道理不应该出现你说的情况!我做了个简单的测试,测试代码如下:
/////////////main.cpp:
#include
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
#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();
}