简体   繁体   中英

QDialog::exec() blocks the application

I currently have a formA that requests input from a user using another form that inherits from QDialog. The form is prompted using QDialog::exec. Now the problem is that there are going to be multiple instances of formA thus whenever any of formA opens up another form as a dialog the entire application blocks.Currently I have something like this

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

Is there a way to make QDialog::exec not block the entire application I just want it to block only the instance of the form it was called on or something like that but definitely not the entire application?

Update: I do not need a blocking window. However I would like for a way to know when the user is done with the input in another form so that the original form can process that data

Call the setWindowModality method on the dialog with Qt::WindowModal as the argument.

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

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

You can use show() instead, and then to grab dialog result you connect the signal of accept to a slot of your formA to treat it, just like:

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

你可以使用show()方法而不是exec() ,因为exec方法有它自己的事件循环。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM