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. Wait for dialog response
Forum Updated to NodeBB v4.3 + New Features

Wait for dialog response

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 5 Posters 8.9k Views 4 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    What kind of dialog do you want to call ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by
      #3

      Any...
      let's say Dialog of QML.

      To be precise, I have many places when C++ routines called QMessageBox or custom QDialog.
      So it is head-breaking how to split every of those functions and do not spoil the logic that just works.
      So if there is any way how to ie.:

      • from a place where dialog was called, send a signal for a dialog
      • then freeze C++ there by some mutex
      • respond for a signal and perform a dialog on QML side
      • get returned value and unlock the mutex
      • continue C++ routine with returned value

      But I'm not sure is it possible or wise and maybe there is easiest way to do it,
      so any clue is appreciated

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Can you show an example of such a code path ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SeeLookS Offline
          SeeLookS Offline
          SeeLook
          wrote on last edited by
          #5
          void someMethod(int param) {
            int var1, var2;
            // some preparation for dialog...
          
            // C++ way to display a dialog and wait for response
            auto myDialog = new MySummaryDialog(param);
            int returnValue = mySummaryDialog::exec();
          
            // possible QML way: emit getSummaryDialog(param);
            // HOW TO lock code here until QML dialog close
          
            // continuation of someMethod() routines, depends on many variables declared inside
            // a few combinations of:
            if (returnValue == var1) {
              // ...
            } else if (returnValue == var2) {
              // ...
            } // else etc...
          
          }
          
          1 Reply Last reply
          0
          • Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #6

            @SeeLook what about using Dialog component from QML? It implements pretty much the same paradigm as old QDialog... See example

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            SeeLookS 1 Reply Last reply
            0
            • Pablo J. RoginaP Pablo J. Rogina

              @SeeLook what about using Dialog component from QML? It implements pretty much the same paradigm as old QDialog... See example

              SeeLookS Offline
              SeeLookS Offline
              SeeLook
              wrote on last edited by
              #7

              @Pablo-J.-Rogina
              Thanks for response.

              Unfortunately all QML dialogues (either Dialog or MessageBox) exists in parallel with code that invoked it.

              Dialog {
                id: someDialog
              }
              
              function callDialog() {
                someDialog.open()
                // I would expect here to know what user did to the dialog but it is not a case of QML (declarative programming)
              }
              

              So I'm asking is it possible to bend this situation?

              mrjjM 1 Reply Last reply
              0
              • SeeLookS SeeLook

                @Pablo-J.-Rogina
                Thanks for response.

                Unfortunately all QML dialogues (either Dialog or MessageBox) exists in parallel with code that invoked it.

                Dialog {
                  id: someDialog
                }
                
                function callDialog() {
                  someDialog.open()
                  // I would expect here to know what user did to the dialog but it is not a case of QML (declarative programming)
                }
                

                So I'm asking is it possible to bend this situation?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #8

                @SeeLook
                Hi
                QML dialogs can be modal too ( modal = wait for ok/cancel)

                Dialog {
                    id: dialog
                    modal: true
                    standardButtons: Dialog.Ok
                }
                
                1 Reply Last reply
                2
                • Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #9

                  @SeeLook I was able to modify DialogPage.qml from this example I mentioned and by adding a Label at the top level (just after existing Label) I can display what the user input after closing "Input" dialog that pops up when clicking "Input" button in the example...

                  ...
                              text: "Dialog is a popup that is mostly used for short-term tasks "
                                  + "and brief communications with the user."
                          }
                  
                          Label {
                              id: result
                              width: parent.width
                              wrapMode: Label.Wrap
                              horizontalAlignment: Qt.AlignHCenter
                          }
                  
                          Button {
                              text: "Message"
                                   ...
                              Dialog {
                                  id: inputDialog
                  
                                   ...
                                  standardButtons: Dialog.Ok | Dialog.Cancel
                  
                                  onAccepted: {
                                      result.text = "user: " + user.text + " password: " + password.text
                                  }
                                    ...
                                    ...
                                      TextField {
                                          id: user
                                          focus: true
                                          placeholderText: "Username"
                                          Layout.fillWidth: true
                                      }
                                      TextField {
                                          id: password
                                          placeholderText: "Password"
                                          echoMode: TextField.PasswordEchoOnEdit
                                          Layout.fillWidth: true
                                      }
                  ...
                  

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  3
                  • SeeLookS Offline
                    SeeLookS Offline
                    SeeLook
                    wrote on last edited by
                    #10

                    @mrjj , @Pablo-J-Rogina
                    Thank You for the clue.
                    But Dialog of Qt Quick 2 (which has modal property) is rather like a popup - it has no any titlebar and frame. I'm using that one from import QtQuick.Dialogs 1.3.
                    However I will reconsider it.
                    This dialog business is messy for me....

                    1 Reply Last reply
                    0
                    • Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #11

                      @SeeLook I'm not trying to convince you about Quick Controls 2, but I think it's the way to go.
                      Also, to make an informed decision please take a look at Dialog details:

                      Dialog's title is displayed by a style-specific title bar that is assigned as a dialog header by default.

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      1
                      • SeeLookS Offline
                        SeeLookS Offline
                        SeeLook
                        wrote on last edited by
                        #12

                        To Quick Controls 2 I'm rather convinced, with this single exception... :-)
                        But really, You opened my eyes for some facts about those dialogs. I have to digest that and weigh what will be more suitable for my app.
                        So I'm quite satisfied with Your answers.
                        Thank You a lot.

                        1 Reply Last reply
                        1
                        • I Offline
                          I Offline
                          iaggo
                          wrote on last edited by iaggo
                          #13

                          Hi, Yes it's possible. You can pass your dialog by context in the main.cpp file like that:

                          ResetDialog* resetDialog = new ResetDialog();
                          engine.rootContext()->setContextProperty("resetDialog", resetDialog);
                          

                          and catch the result like that in the qml file:

                          Connections{target: resetDialog; onAccepted: {console.log("I WAS  ACCEPTED"); onRejected: {console.log("I was Rejected")}}}
                          
                          1 Reply Last reply
                          0

                          • Login

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