4

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

MistyD
  • 16,373
  • 40
  • 138
  • 240
  • 1
    @sara not possible all QWidgets must be in the main thread – ratchet freak Sep 12 '13 at 15:21
  • @ratchetfreak it is possible: http://stackoverflow.com/questions/9777911/how-do-i-create-a-window-in-different-qt-threads however not trivial, so I deleted my comment – sara Sep 12 '13 at 15:25

4 Answers4

8

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

kol
  • 27,881
  • 12
  • 83
  • 120
2

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();
ismaelrs
  • 102
  • 4
1

set the modality of the dialog to Qt::WindowModal (the default of QDialog is Qt::ApplicationModal)

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
0

You can use show() method instead of exec(), because exec method has it's own event loop.

Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61