关闭模态对话框关闭程序

关闭模态对话框关闭程序

本文介绍了Qt:关闭模态对话框关闭程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Qt程序中,我有2个窗口(主窗口和子窗口)。在程序中,每次只显示其中一个窗口。主窗口有一个插槽,创建一个模态对话框。现在,让我们说来自子窗口中的按钮点击的信号被发送到该槽。在这种情况下,主窗口被隐藏,子窗口是可见的。对话框显示得很好,但是当对话框关闭时,程序也会关闭,虽然子窗口仍然可见。预期的行为是关闭对话框后,子窗口仍然可见,程序正在运行。什么可能导致这种行为,如何可以解决?任何帮助非常感谢。

In my Qt program I have 2 windows (main and child window). In the program, only one of these windows is shown at a time. Main window has a slot, which creates a modal dialog. Now, let's say a signal from a button click in child window is sent to that slot. In that case, main window is hidden and child window is visible. The dialog is displayed just fine, but when the dialog is closed, the program closes as well, although the child window is still visible. The expected behaviour is that after closing the dialog, the child window is still visible and the program is running. What could cause this behaviour, and how could it be fixed? Any help greatly appreciated.

推荐答案

调用 setQuitOnLastWindowClosed(false); 您的QApplication实例。

Call setQuitOnLastWindowClosed(false); on your QApplication instance.

这篇关于Qt:关闭模态对话框关闭程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:05