【问题标题】:QDialog::exec() blocks the applicationQDialog::exec() 阻塞应用程序
【发布时间】:2013-09-17 01:38:06
【问题描述】:

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

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

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

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

【问题讨论】:

标签: c++ qt


【解决方案1】:

设置对话框的modalityQt::WindowModal(QDialog的默认为Qt::ApplicationModal

【讨论】:

    【解决方案2】:

    在对话框中调用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.
    

    Source

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        您可以使用 show() 代替,然后将 accept 信号连接到 formA 的插槽以获取对话结果以对其进行处理,就像:

        connect(formUserInputRequired, SIGNAL(accept()), this, SLOT(acceptClicked());
        formUserInputRequired->show();
        

        【讨论】:

        • connect 中缺少一个右括号
        猜你喜欢
        • 2016-02-09
        • 1970-01-01
        • 1970-01-01
        • 2016-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-24
        • 1970-01-01
        相关资源
        最近更新 更多