开发者

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开发者_JAVA百科 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?


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

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


If you start with a QDialog, you can use the exec() method to block until the dialog is dismissed. You can put your Declarative View onto the dialog.

As far as if this is a reasonable use of Qt, it depends on your needs. In many cases, users will prefer nonmodal dialogs where they can continue doing other things with the dialog open. A blocking function is uaually not the most convenient way to present such a nonmodal window. Normally, the "correct" thing to do is just connect a signal to a handler which executes whenever your dialog is dismissed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜