Unsolved Absolutely no way to have blocking dialog (or something similar) in qml?
-
I know qml is a declarative language instead of imperative but when some numbers of different actions need to be executed based to the various choices from the user have a blocking dialog (like C++ exec()) will help a lot in write simplest code. Qml is all asyncronous but someone know if exist a sort of workaround to "simulate" in some way a blocking modal dialog that will "return" only once the user made a choice? I guess is quite hard but I ask just in case. In substitution is there some particular technics to manage different actions/decision allowing using some generic reusable components? For example a generic MessageBox component...
-
I haben't implemented a blocking dialog, but I think it could be possible with the
Popup
component. Especially theclosePolicy
property looks promising. (see https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html#closePolicy-prop)I am not sure if it's necessary, but you might also need to set the
enabled
property of your underlyingItem
to false so that it doesn't receive any keyboard or mouse events during the popup is opened. -
closePolicy instruct the control regarding the possible options for close the popup, that can be by pressing in some other part of the screen not covered by the popup area, by pressing esc key and so on but doesn't block che code in await of some input.
-
@Suppaman Yeah, but what if you set the
closePolicy
accordingly and as soon as the dialog opens you disable the other Item(s) thar are shown on the screen by settingenabled
to false. That way the other items won't receive any keyboard- and mouse events during the dialog is opened which forces the user to click on the dialog before he can do anything else. -
What you described is a modal dialog that you can obtain by simply set the "modal" property to true, no need to make additional operations. My question is more code related. In the javascript code creating the qml modal dialog, after called the open() function for show the dialog the code will continue immediately to the next instructions since qml is all asyncronous. On the contrary, in C++, once called the method exec() the code will stop here waiting for the user action and, after done, will continue. I would to know if exist some workaround to get same result in qml javascript. I'm quite sure don't exist but just in case I try to ask.
-
@Suppaman oh, sorry didn't get that. I don't know any functionality which can do this, but maybe someone else has an idea.
I could imagine that it's also a rare usecase. Because usually I would want that the GUI event loop continues, as there might be things that need to get processed
-
The C++ exec() method run an "internal" secondary events processing loop that allow the GUI to continue work as expected. Unfortunately it seem is not possible to use same way with qml since the qml "engine" could return troubles if run in a secondary loop...
Anyway thak you to find time in try to help me. ^_^ -
@Suppaman said in Absolutely no way to have blocking dialog (or something similar) in qml?:
What you described is a modal dialog that you can obtain by simply set the "modal" property to true, no need to make additional operations. My question is more code related. In the javascript code creating the qml modal dialog, after called the open() function for show the dialog the code will continue immediately to the next instructions .....
I'm using modal Dialogs and in my qml code after open() the dialog I have a 'return' so no more code will be executed
don't understand your problemunder Android there were situations where the BACK key can be recognized while a modal Popup is open.
so I'm always setting a var 'modalDialogRunning" to true when opening a Dialog and false from closing.
from my key listener I check if 'modalDialogRunning' if BACK key recognized and let the user know by a Toast "please finish Dialog first"
perhaps you're connected to some SIGNALs from C++ (per ex QNAM finished a request) from where qml code can be executed. simply check the 'modalDialogRunning' flagBTW: all my experiences are with QtQuickCOntrols2