在 Qt 中关闭新的非子窗口
我正在尝试制作 2 个窗户。 2nd 应该在 1st 中调用。 我不将它们与孩子->父母联系起来。 但是当我打电话给第二个窗口并关闭它时,第一个窗口也关闭了。 我应该怎么办? 这两个窗口都继承自 QWidget。 C++ 和 Qt
抱歉我的描述很糟糕。 我有一个主窗口。 从 QMainWindow 继承的类。 我创建了第二个窗口。 继承自QWidget的类。 在第一个(主窗口)中,我正在创建并调用第二个窗口,
ConfigWindow *ConfWindow = new ConfigWindow();
ConfWindow->show();
而不提供指向父级的链接。 一切正常,但是当我关闭第二个窗口(配置窗口)时,我的主窗口也关闭了。 我不需要这个。 我应该做什么来阻止配置窗口关闭后关闭主窗口。
希望描述的好一点。
我的第一个窗口有这个标志:
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
没有它们一切都很好。 如果我需要在窗口中使用该标志,我可以更改某些内容吗?
i'm trying to make 2 windows. 2nd should be called in 1st. I don't connect them child->parent.
But when i called 2nd window and closed it 1st window closed too. What should i do?
Both windows are inhereted from QWidget.
C++ and Qt
Sorry for my poor describe.
I have a main window. Class inherited from QMainWindow. That i created 2nd window. Class inherited from QWidget.
In first (main window) i'm creating and calling 2nd window
ConfigWindow *ConfWindow = new ConfigWindow();
ConfWindow->show();
Without giving link to parent. Everything works fine, but when i close 2nd window (config-window) my main window is closing too. I needn't in this. What should i do to block closing main window after config-window closing.
Hope describe a little better.
My first window has this flags:
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
Without them everything is fine. Could i change something if i need that flags in my window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要类似的东西:
这是测试程序:http://pastebin.com/f5903c5f4。
请注意,现在您需要显式调用quit() 在主窗口的析构函数中。
如果您阅读 QApplication::quitOnLastWindowClosed 文档,您会发现:
因为您的主窗口是(无框架)工具窗口,所以它确实很重要。 这使得 ConfWindow 成为唯一的非子窗口顶级小部件。 因此,如果您关闭 ConfWindow,它会导致应用程序实例退出。
You need something like:
Here is the test program: http://pastebin.com/f5903c5f4.
Beware, now you need to explicitly call quit() in the destructor of your main window.
If you read QApplication::quitOnLastWindowClosed documentation, you will find out that:
Because your main window is a (frameless) tool window, it does count. That leaves ConfWindow as the only non sub-windows top-level widget. Thus, if you close ConfWindow, it provokes the application instance to quit.
如果这是代码,那么 Qt 中存在一个巨大的错误。
上面的代码永远不应该关闭您的第一个 Windows,一定还有其他问题。
应用程序是否已关闭或崩溃?
备注
谁在删除configWindow? 有一个
Qt::WA_DeleteOnClose
属性可以在窗口关闭后将其删除。If this is the code, then there is a huge bug in Qt.
The code above should never close your first Windows, there must be something else wrong.
Is the application closed or does it crash?
Remark
Who is deleting configWindow? There is a
Qt::WA_DeleteOnClose
attribute that deletes the window after it is closed.