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. does not return from exec()
Forum Updated to NodeBB v4.3 + New Features

does not return from exec()

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 5 Posters 2.8k Views 3 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.
  • E Offline
    E Offline
    explorer100
    wrote on last edited by explorer100
    #1

    In non-modal mode - when a new dialog is invoked, the exec() of any other running dialog no longer returns with a value. Control of all other active dialogs goes to their respective Accept() and Reject() functions if specified and stops there. Basically only one exec() at a time. Is this the correct behaviour? and is there a way to circumvent this behaviour without going to modal mode?

    jsulmJ 1 Reply Last reply
    0
    • E explorer100

      In non-modal mode - when a new dialog is invoked, the exec() of any other running dialog no longer returns with a value. Control of all other active dialogs goes to their respective Accept() and Reject() functions if specified and stops there. Basically only one exec() at a time. Is this the correct behaviour? and is there a way to circumvent this behaviour without going to modal mode?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @explorer100 said in does not return from exec():

      Basically only one exec() at a time. Is this the correct behaviour?

      Yes, this is correct behavior. How would you invoke exec() more than once at the same time? exec() is blocking. Use show() instead of exec() if you don't want to have modal behavior.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply
      0
      • jsulmJ jsulm

        @explorer100 said in does not return from exec():

        Basically only one exec() at a time. Is this the correct behaviour?

        Yes, this is correct behavior. How would you invoke exec() more than once at the same time? exec() is blocking. Use show() instead of exec() if you don't want to have modal behavior.

        E Offline
        E Offline
        explorer100
        wrote on last edited by
        #3

        @jsulm thank you so much for the clarification. But this means, all (OK, Cancel, window close) processing will need to be handled in the dialog Accept() and Reject() functions. Not external to the dialog. Is this correct?

        jsulmJ 1 Reply Last reply
        0
        • E explorer100

          @jsulm thank you so much for the clarification. But this means, all (OK, Cancel, window close) processing will need to be handled in the dialog Accept() and Reject() functions. Not external to the dialog. Is this correct?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @explorer100 said in does not return from exec():

          But this means, all (OK, Cancel, window close) processing will need to be handled in the dialog Accept() and Reject() functions

          Not sure what you mean here. It's the dialog itself handling OK/Cancel.
          If you want to be notified that a dialog was closed connect a slot to https://doc.qt.io/qt-6/qdialog.html#finished

          One correction to what I wrote before: there is also https://doc.qt.io/qt-6/qdialog.html#open instead of show()

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            explorer100
            wrote on last edited by explorer100
            #5

            What I meant is the exec() returns values of 0,1,-1 and possibly others indicating if dialog accept/reject were selected by the user (through for example clicking OK button). Based on this return, processing can take place of the OK/Cancel outside of the dialog. But with non-modal it seems that approach cannot be done, and all OK/Cancel processing would need to be handled from within the dialog itself - in the Accept() Reject() functions of the dialog. Is this correct?

            jsulmJ 1 Reply Last reply
            0
            • E explorer100

              What I meant is the exec() returns values of 0,1,-1 and possibly others indicating if dialog accept/reject were selected by the user (through for example clicking OK button). Based on this return, processing can take place of the OK/Cancel outside of the dialog. But with non-modal it seems that approach cannot be done, and all OK/Cancel processing would need to be handled from within the dialog itself - in the Accept() Reject() functions of the dialog. Is this correct?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @explorer100 said in does not return from exec():

              with non-modal it seems that approach cannot be done

              Of course it can be done. Did you check the link I gave you (https://doc.qt.io/qt-6/qdialog.html#finished)? This signal provides the result of the dialog as parameter. So, again: connect a slot to this signal and check the "result" parameter to react accordingly.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • E Offline
                E Offline
                explorer100
                wrote on last edited by
                #7

                Great.. thank you.. I will check it.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  explorer100
                  wrote on last edited by
                  #8

                  Thank you very much.. works beautifully!

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    explorer100
                    wrote on last edited by explorer100
                    #9

                    I tried this method for a modal dialog .. (connecting the finished() and using show()), but the dialog did not show (actually shows up then immediately disappears).
                    Maybe a mistake on my side? or is that the expected behavior for a modal dialog?

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • E explorer100

                      I tried this method for a modal dialog .. (connecting the finished() and using show()), but the dialog did not show (actually shows up then immediately disappears).
                      Maybe a mistake on my side? or is that the expected behavior for a modal dialog?

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @explorer100 said in does not return from exec():

                      Maybe a mistake on my side?

                      I would guess it's a lack of c++ knowledge - what's the lifetime of the object?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      E 1 Reply Last reply
                      3
                      • Christian EhrlicherC Christian Ehrlicher

                        @explorer100 said in does not return from exec():

                        Maybe a mistake on my side?

                        I would guess it's a lack of c++ knowledge - what's the lifetime of the object?

                        E Offline
                        E Offline
                        explorer100
                        wrote on last edited by explorer100
                        #11

                        @Christian-Ehrlicher I'm not sure what you mean by "lifetime of the object".. you mean difference in time of before it shows up and after it disappears? its nano seconds.

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

                          Hi,

                          The lifetime of an object correspond to where it's created until it's destroyed. Typically, in your case, you are likely creating your dialog on the stack in a function and that variable is thus destroyed when the end of the function is reached.

                          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
                          3
                          • E explorer100

                            @Christian-Ehrlicher I'm not sure what you mean by "lifetime of the object".. you mean difference in time of before it shows up and after it disappears? its nano seconds.

                            E Offline
                            E Offline
                            explorer100
                            wrote on last edited by explorer100
                            #13

                            @explorer100 ok great! yes you are right.. it is created in a function, not in the main program. that is why it disappeared. ok. so when it is in modal mode, with exec(), the function will remain.. makes sense. thanks,

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              explorer100
                              wrote on last edited by
                              #14

                              why some dialogs remain visible even after program terminates?

                              JonBJ 1 Reply Last reply
                              0
                              • E explorer100

                                why some dialogs remain visible even after program terminates?

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #15

                                @explorer100 said in does not return from exec():

                                why some dialogs remain visible even after program terminates?

                                No dialog or window could remain visible if your program terminates. If you still see them that means your program has not terminated, even if you think it has. For example, just because your main window closes does not automatically mean your program has terminated. By default a Qt UI application closes when the last top-level window closes. If your windows all have that as an ancestor they will close too, and the application will exit. But if, say, you create a modeless, non-parented top-level window that will not close when the main window does, and the application will not close while that is still open.

                                1 Reply Last reply
                                1
                                • E Offline
                                  E Offline
                                  explorer100
                                  wrote on last edited by
                                  #16

                                  "But if, say, you create a modeless, non-parented top-level window that will not close when the main window does, and the application will not close while that is still open."

                                  I think I have done exactly that. using:

                                  if name == "main":

                                  app = QApplication(sys.argv)
                                  window = MainWindow()
                                  window.show()
                                  sys.exit(app.exec())
                                  

                                  How else would you do it?

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

                                    By default, the application should quit after the last top level window is closed.
                                    You can change that behaviour but it's an explicit thing you have to code.

                                    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
                                    1
                                    • E explorer100

                                      "But if, say, you create a modeless, non-parented top-level window that will not close when the main window does, and the application will not close while that is still open."

                                      I think I have done exactly that. using:

                                      if name == "main":

                                      app = QApplication(sys.argv)
                                      window = MainWindow()
                                      window.show()
                                      sys.exit(app.exec())
                                      

                                      How else would you do it?

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #18

                                      @explorer100
                                      If that code is all you have, and you do not change default quitOnLastWindowClosed to False, your application should fully exit when you close your window. Why don't you test just that program as it is with nothing else? But if you have been doing the sort of things you were talking about with other dialogs then it depends what you did with them.

                                      1 Reply Last reply
                                      0
                                      • E Offline
                                        E Offline
                                        explorer100
                                        wrote on last edited by explorer100
                                        #19

                                        The main window goes invisible, but the other dialogs who have main window as a parent but are non-modal. They stay visible. what I am doing is pressing the X on the top right of the window to test this. and as you said, the app does not actually close (I can see from the IDE that it did not actually close).

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

                                          Closing a window does not mean it gets destroyed immediately. You have multiple top level windows hence your application is still alive due to these other windows.

                                          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
                                          1

                                          • Login

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