4

我目前有一个 formA,它使用从 QDialog 继承的另一个表单请求用户输入。使用 QDialog::exec 提示表单。现在的问题是将有多个formA实例,因此每当formA中的任何一个打开另一个表单作为对话框时,整个应用程序都会阻塞。目前我有这样的东西

if(formUserInputRequired->exec()==1) //Block until the user selects from a form
{
}

有没有办法让 QDialog::exec 不阻塞整个应用程序我只是希望它只阻塞它被调用的表单的实例或类似的东西,但绝对不是整个应用程序?

更新:我不需要阻塞窗口。但是我想要一种方法来知道用户何时完成了另一种形式的输入,以便原始表单可以处理该数据

4

4 回答 4

8

使用作为参数调用setWindowModality对话框上的方法。Qt::WindowModal

Qt::NonModal          0  The window is not modal and does not block input to other windows.
Qt::WindowModal       1  The window is modal to a single window hierarchy and blocks input to its parent window, all grandparent windows, and all siblings of its parent and grandparent windows.
Qt::ApplicationModal  2  The window is modal to the application and blocks input to all windows.

资源

于 2013-09-12T15:22:38.047 回答
2

您可以改用 show() ,然后获取对话框结果,将 accept 信号连接到 formA 的一个插槽来处理它,就像:

connect(formUserInputRequired, SIGNAL(accept()), this, SLOT(acceptClicked());
formUserInputRequired->show();
于 2013-09-12T15:55:53.217 回答
1

将对话框的模态Qt::WindowModal设置为(QDialog 的默认值为Qt::ApplicationModal

于 2013-09-12T15:22:37.170 回答
0

您可以使用show()method 代替exec(),因为execmethod 有它自己的事件循环。

于 2013-09-12T15:29:45.443 回答