• 5599阅读
  • 4回复

为什么父窗口关闭了,子窗口还在? [复制链接]

上一主题 下一主题
离线huyoujun
 

只看楼主 倒序阅读 楼主  发表于: 2008-04-03
— 本帖被 XChinux 执行加亮操作(2008-04-04) —
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi(this);
    connectdialog = new ConnectDialog(this);
    connectdialog ->setParent(this)
}
我让connectdialog show()后,然后关闭MainWindow,可是这个connectdialog 还在,进程也还在,请问为什么啊?
离线zncggaofei
只看该作者 1楼 发表于: 2008-04-04
因为是QDialog ,
A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself). It will also share the parent's taskbar entry.
一个dialog总是顶级的,如果它有父窗口,只会改变默认出现的位置在父窗体的中央
Modeless dialogs are displayed using show(), which returns control to the caller immediately.
而connectdialog show()之后,控制权立刻就给了调用者即connectdialog
There is someone that is coming or passing away in your life around the clock, so you may lose sight of those seen, and forget those remembered. There is gain and loss in your life, so you may catch sight of those unseen, and remember those forgotten. Nevertheless, doesn’t the unseen exist for sure? Will the remembered remain forever?
离线captain08
只看该作者 2楼 发表于: 2008-04-04
有什么解决办法吗?
离线huyoujun

只看该作者 3楼 发表于: 2008-04-06
没有什么好办法吗?有什么参数可以设置的吗?目前我是在主窗口的关闭事件里处理其他的窗口的关闭,我觉得不应该这么麻烦的啊。
离线captain08
只看该作者 4楼 发表于: 2008-04-08
在构造函数写
setAttribute(Qt::WA_DeleteOnClose)
就可以。
快速回复
限100 字节
 
上一个 下一个