• 4851阅读
  • 2回复

请问关于窗口间的父子关系的问题 [复制链接]

上一主题 下一主题
离线kytexzy
 

只看楼主 倒序阅读 楼主  发表于: 2006-11-09
我的一个窗口A中有一个按钮,当我点击按钮时,会弹出一个新的对话框,按理来说这个对话框应该是原来窗口A的孩子,可是当我关闭窗口A时这个对话框却没有关闭,请问我怎么用代码表示这种父子关系?

对话框的构造函数如下:
TypeSet::TypeSet(QWidget *parent)
  : QDialog(parent)
{
  ui.setupUi(this);
 
 
}

打开对话框的函数如下:
void WorkRecord::typeSet()
{
  TypeSet *typeSet = new TypeSet(this);
  typeSet->show();
}
[ 此贴被XChinux在2006-11-16 22:56重新编辑 ]
try to find forgiveness for yourself and forgive others
离线kytexzy

只看该作者 1楼 发表于: 2006-11-10
请问我怎样才能在我关闭父窗口时把子窗口也关闭?
try to find forgiveness for yourself and forgive others
离线penguinfish

只看该作者 2楼 发表于: 2006-11-13
你的代码已经表明了父子关系,按道理不应该出现你说的情况!我做了个简单的测试,测试代码如下:

/////////////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();
}
快速回复
限100 字节
 
上一个 下一个