Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Main thread waiting until dialog completion
Qt 6.11 is out! See what's new in the release blog

Main thread waiting until dialog completion

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 4.8k Views 1 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    A better design is simply to emit a signal when dialog is finished.
    Then main can do what task you plan.
    Generally, you do not pause or make main tread wait
    as it lags the app , prevent events flowing and
    its just bad design.

    Can I ask why you want to wait ?

    1 Reply Last reply
    1
    • HunterMetcalfeH Offline
      HunterMetcalfeH Offline
      HunterMetcalfe
      wrote on last edited by
      #3

      I realize that. This particular event arises when multiple error messages are received. I handle each of those with a dialog as whether the user wants to continue or not. In the event that multiple errors occur I receive the warning "QDialog::exec: Recursive call detected"

      The reason I would block or make the main thread wait is that nothing behind the scenes should be processed until the users input is received.

      1 Reply Last reply
      0
      • HunterMetcalfeH Offline
        HunterMetcalfeH Offline
        HunterMetcalfe
        wrote on last edited by
        #4

        Really I'm trying to understand why the QDialog::exec: Recursive call detected is being outputted.

        mrjjM 1 Reply Last reply
        0
        • HunterMetcalfeH HunterMetcalfe

          Really I'm trying to understand why the QDialog::exec: Recursive call detected is being outputted.

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

          @HunterMetcalfe
          Hi
          Yes me too.
          You are not using threads ?

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

            Hi! The main responsibility of the main thread, aka GUI thread, is to handle both events from the OS and the GUI. If your application's design requires you to block the main thread, then your design is flawed.

            HunterMetcalfeH 1 Reply Last reply
            0
            • HunterMetcalfeH Offline
              HunterMetcalfeH Offline
              HunterMetcalfe
              wrote on last edited by
              #7

              Okay I figured out the solution. I will post the relevant code. Hopefully it helps others.

              In the constructor I have

              connect( singleton,
                     SIGNAL( ErrorReceived( ErrorMsg ) ),
                     this,
                     SLOT( ErrorReceived( ErrorMsg ) ),
                     Qt::BlockingQueuedConnection );
              
              

              In my slot "ErrorReceived"

              void Panel::ErrorReceived( ErrorMsg msg )
              {
                 m_errorDialog->exec();
              }
              

              The solution is to use a

              Qt::BlockingQueuedConnection
              

              This allows the user to work with the current dialog as to whether or not they want to continue. In the meanwhile future errors will queue. After completing, the next dialog will popup, while still allowing the main thread to receive updates.

              @mrjj Yes this application is multi-threaded

              1 Reply Last reply
              1
              • ? A Former User

                Hi! The main responsibility of the main thread, aka GUI thread, is to handle both events from the OS and the GUI. If your application's design requires you to block the main thread, then your design is flawed.

                HunterMetcalfeH Offline
                HunterMetcalfeH Offline
                HunterMetcalfe
                wrote on last edited by
                #8

                @Wieland Thanks for the reply, I didn't word it entirely well, but I have posted my solution below.

                mrjjM 1 Reply Last reply
                0
                • HunterMetcalfeH HunterMetcalfe

                  @Wieland Thanks for the reply, I didn't word it entirely well, but I have posted my solution below.

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

                  @HunterMetcalfe
                  Hi
                  so the "Recursive call detected" came from being inside dialog .exec() and then
                  a signal to open yet another Dialog comes and that is handled inside the current exec() ?

                  HunterMetcalfeH 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @HunterMetcalfe
                    Hi
                    so the "Recursive call detected" came from being inside dialog .exec() and then
                    a signal to open yet another Dialog comes and that is handled inside the current exec() ?

                    HunterMetcalfeH Offline
                    HunterMetcalfeH Offline
                    HunterMetcalfe
                    wrote on last edited by
                    #10

                    @mrjj Yes, that seemed to be the case. I had even tried disconnecting the slot from the signal while executing the dialog, then reconnecting, but that didn't fix the issue.

                    mrjjM 1 Reply Last reply
                    0
                    • HunterMetcalfeH HunterMetcalfe

                      @mrjj Yes, that seemed to be the case. I had even tried disconnecting the slot from the signal while executing the dialog, then reconnecting, but that didn't fix the issue.

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

                      @HunterMetcalfe
                      Hmm, that is a bit odd as how would it then open the dialog (again) but
                      i guess we will never really know. :)

                      HunterMetcalfeH 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @HunterMetcalfe
                        Hmm, that is a bit odd as how would it then open the dialog (again) but
                        i guess we will never really know. :)

                        HunterMetcalfeH Offline
                        HunterMetcalfeH Offline
                        HunterMetcalfe
                        wrote on last edited by
                        #12

                        @mrjj I also believed that would've been the functionality. Funny thing is now when the user clicks no on the dialog, I don't want anymore popups to be displayed. I considered doing a bool variable that tracks whether the user has clicked no, but it seems to need some more thought out logic.

                        So if( !no)

                        dialog->exec();

                        something like that.

                        mrjjM 1 Reply Last reply
                        0
                        • HunterMetcalfeH HunterMetcalfe

                          @mrjj I also believed that would've been the functionality. Funny thing is now when the user clicks no on the dialog, I don't want anymore popups to be displayed. I considered doing a bool variable that tracks whether the user has clicked no, but it seems to need some more thought out logic.

                          So if( !no)

                          dialog->exec();

                          something like that.

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

                          @HunterMetcalfe
                          Hmm
                          But when will you know that pop ups are ok again ?
                          You could use a timer, so if a new POP is seen X secs after user says no, they are ignored.

                          But it really depends when its ok again to popup after last "no"

                          HunterMetcalfeH 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @HunterMetcalfe
                            Hmm
                            But when will you know that pop ups are ok again ?
                            You could use a timer, so if a new POP is seen X secs after user says no, they are ignored.

                            But it really depends when its ok again to popup after last "no"

                            HunterMetcalfeH Offline
                            HunterMetcalfeH Offline
                            HunterMetcalfe
                            wrote on last edited by
                            #14

                            @mrjj Yes, that's the trouble - determining when popups will be okay again.

                            mrjjM 1 Reply Last reply
                            0
                            • HunterMetcalfeH HunterMetcalfe

                              @mrjj Yes, that's the trouble - determining when popups will be okay again.

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

                              @HunterMetcalfe

                              Do the errors have any ID so you can know its from same batch ?

                              HunterMetcalfeH 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @HunterMetcalfe

                                Do the errors have any ID so you can know its from same batch ?

                                HunterMetcalfeH Offline
                                HunterMetcalfeH Offline
                                HunterMetcalfe
                                wrote on last edited by
                                #16

                                @mrjj No they don't but I was able to work around that using a flag in my singleton.

                                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