• 4991阅读
  • 3回复

qt child 与 parent的关系疑问(不可见状态) [复制链接]

上一主题 下一主题
离线yuangong
 
只看楼主 倒序阅读 楼主  发表于: 2009-12-03
场景如下:
new 一个MainWindow对象(继承QMainWindow),重载CloseEvent,当关闭window时调用hide()隐藏window
window会每2S create一个dialog。
现在有一个问题,当window没有隐藏的时候,每2S会create 一个Dialog。但是当window不可见(隐藏后), 当弹出dialog后关闭dialog会导致window也关闭。
请问为什么会这样?
部分代码如下:
-------------------MainWindow.cpp-------------
connect(timer, SIGNAL(timeout()), this, SLOT(CreateDialog()));

void MainWindow::closeEvent(QCloseEvent *event)
{
    hide();
    event->ignore();
}

void MainWindow::CreateDialog()
{
    Dialog dialog(this);
    dialog.exec();
}
-----------------Dialog.cpp-----------------
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::Dialog)
{
    m_ui->setupUi(this);
}
----------------------------------------------------------------------------------------------------------------------------------

离线dbzhang800

只看该作者 1楼 发表于: 2009-12-03
你是在找这个么?
void QApplication::lastWindowClosed ()   [signal]
This signal is emitted from QApplication::exec() when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed.
By default,
this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus
QApplication implicitly quits when this signal is emitted.
This feature can be turned off by setting quitOnLastWindowClosed to false.
离线yuangong
只看该作者 2楼 发表于: 2009-12-03
感谢解答,加上setQuitOnLastWindowClosed(false)后即使隐藏也不会退出了。
离线yb824
只看该作者 3楼 发表于: 2009-12-03
加上setQuitOnLastWindowClosed(false) MainWindow在隐藏的时候关闭diglog是不会推出的啊
快速回复
限100 字节
 
上一个 下一个