Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Absolutely no way to have blocking dialog (or something similar) in qml?
Qt 6.11 is out! See what's new in the release blog

Absolutely no way to have blocking dialog (or something similar) in qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 5.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Schluchti
      wrote on last edited by
      #2

      I haben't implemented a blocking dialog, but I think it could be possible with the Popup component. Especially the closePolicy 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 underlying Item to false so that it doesn't receive any keyboard or mouse events during the popup is opened.

      Want to read more about Qt?

      https://gympulsr.com/blog/qt/

      Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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.

        S 1 Reply Last reply
        0
        • ? A Former User

          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.

          S Offline
          S Offline
          Schluchti
          wrote on last edited by
          #4

          @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 setting enabled 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.

          Want to read more about Qt?

          https://gympulsr.com/blog/qt/

          Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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.

            S ekkescornerE 2 Replies Last reply
            0
            • ? A Former User

              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.

              S Offline
              S Offline
              Schluchti
              wrote on last edited by
              #6

              @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

              Want to read more about Qt?

              https://gympulsr.com/blog/qt/

              Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                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. ^_^

                1 Reply Last reply
                0
                • ? A Former User

                  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.

                  ekkescornerE Offline
                  ekkescornerE Offline
                  ekkescorner
                  Qt Champions 2016
                  wrote on last edited by ekkescorner
                  #8

                  @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 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

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved