Search code examples
c++qtblockingqml

Qt Blocking call to display dialog?


I am mucking about with Qt and QML.

So I would like to have a blocking call to display a dialog and retrieve user input. The call is guaranteed not to be on the current UI thread.

I have QDeclarativeView object that I have created using QML. I can display it using the show method(). But now I want to block until the user hits OK/Cancel, at which point I will extract the info from the object and return the information to the caller.

So the questions are:

  • Is this a reasonable way to use QT
  • If so how do I make the current thread block?

Solution

  • Use a Qt::BlockingQueuedConnection connected to the QDialog::exec() slot.

    http://doc.qt.io/qt-5/qt.html#ConnectionType-enum