Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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
Popupcomponent. Especially the
closePolicyproperty 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
enabledproperty of your underlying
Itemto 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
closePolicyaccordingly and as soon as the dialog opens you disable the other Item(s) thar are shown on the screen by setting
enabledto 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.
@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. ^_^
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 problem
under 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' flag
BTW: all my experiences are with QtQuickCOntrols2