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. Who closes application on Escape?
QtWS25 Last Chance

Who closes application on Escape?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.3k Views
  • 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on 12 Nov 2021, 13:58 last edited by
    #1

    Hi,

    I accidently hit Escape and the application was closed as fast as possible.
    I was astonished, as I did not code that feature.

    And as I don't want that feature, I tried to find the source of it.
    Adding keyPressEvent to MainWindow did not work.
    So I started Application in debugger and put a breakpoint at QApplication::event() but debugger did not stop at Escape.

    According Qt documentation of QKeySequence there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.

    Debugger just says that application has finished with exit-code 0.

    How can I find out, who is responsible for closing application?

    J P 3 Replies Last reply 12 Nov 2021, 14:00
    0
    • D django.Reinhard
      12 Nov 2021, 13:58

      Hi,

      I accidently hit Escape and the application was closed as fast as possible.
      I was astonished, as I did not code that feature.

      And as I don't want that feature, I tried to find the source of it.
      Adding keyPressEvent to MainWindow did not work.
      So I started Application in debugger and put a breakpoint at QApplication::event() but debugger did not stop at Escape.

      According Qt documentation of QKeySequence there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.

      Debugger just says that application has finished with exit-code 0.

      How can I find out, who is responsible for closing application?

      J Offline
      J Offline
      JonB
      wrote on 12 Nov 2021, 14:00 last edited by
      #2

      @django-Reinhard
      If you have an application consisting of just a QMainWindow I do not believe Escape will close/exit it. Maybe you have something else, I don't know.

      1 Reply Last reply
      1
      • D django.Reinhard
        12 Nov 2021, 13:58

        Hi,

        I accidently hit Escape and the application was closed as fast as possible.
        I was astonished, as I did not code that feature.

        And as I don't want that feature, I tried to find the source of it.
        Adding keyPressEvent to MainWindow did not work.
        So I started Application in debugger and put a breakpoint at QApplication::event() but debugger did not stop at Escape.

        According Qt documentation of QKeySequence there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.

        Debugger just says that application has finished with exit-code 0.

        How can I find out, who is responsible for closing application?

        P Offline
        P Offline
        Pl45m4
        wrote on 12 Nov 2021, 14:07 last edited by Pl45m4 11 Dec 2021, 14:15
        #3

        @django-Reinhard

        Every QDialog subclass will receive a reject on ESC-key and close afterwards (or whatever you do when it got rejected).

        Edit:

        And even if you have a QMainWindow but it's hidden at this moment, the dialog will receive a reject and your QApp will exit properly.

        • https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

        Damn @J-Hilk, I was editing my post, when you wrote the same I was about to write :)


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        2
        • J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 12 Nov 2021, 14:12 last edited by J.Hilk 11 Dec 2021, 14:17
          #4

          to add to @Pl45m4
          if you have a QDialog open, and all other widgets are hidden, and you press esc, than due to
          https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop property, that is by default set to true, your whole program should close


          @Pl45m4 great minds think alike 😎


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          2
          • J Offline
            J Offline
            JonB
            wrote on 12 Nov 2021, 14:28 last edited by
            #5

            I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

            P J 2 Replies Last reply 12 Nov 2021, 14:47
            1
            • J JonB
              12 Nov 2021, 14:28

              I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

              P Offline
              P Offline
              Pl45m4
              wrote on 12 Nov 2021, 14:47 last edited by Pl45m4 11 Dec 2021, 14:49
              #6

              @JonB said in Who closes application on Escape?:

              I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

              There is no other possibility than this... A QMainWindow never closes on ESC by default unless you modify key- and closeEvents.

              Edit:
              It's more likely our 2nd guess... Maybe the QMainWindow was hidden and some dialog the last visible widget.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              J 1 Reply Last reply 12 Nov 2021, 14:48
              1
              • P Pl45m4
                12 Nov 2021, 14:47

                @JonB said in Who closes application on Escape?:

                I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

                There is no other possibility than this... A QMainWindow never closes on ESC by default unless you modify key- and closeEvents.

                Edit:
                It's more likely our 2nd guess... Maybe the QMainWindow was hidden and some dialog the last visible widget.

                J Offline
                J Offline
                JonB
                wrote on 12 Nov 2021, 14:48 last edited by JonB 11 Dec 2021, 14:49
                #7

                @Pl45m4
                I agree, which is what I said. Just I'm sure the OP would have mentioned this vital piece of information if he were using a dialog, another window, or the main window was closed/hidden.... :)

                P 1 Reply Last reply 12 Nov 2021, 14:53
                1
                • J JonB
                  12 Nov 2021, 14:28

                  I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 12 Nov 2021, 14:52 last edited by
                  #8

                  @JonB said in Who closes application on Escape?:

                  I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....

                  your faith in humanity is adorable 😘


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • J JonB
                    12 Nov 2021, 14:48

                    @Pl45m4
                    I agree, which is what I said. Just I'm sure the OP would have mentioned this vital piece of information if he were using a dialog, another window, or the main window was closed/hidden.... :)

                    P Offline
                    P Offline
                    Pl45m4
                    wrote on 12 Nov 2021, 14:53 last edited by Pl45m4 11 Dec 2021, 14:54
                    #9

                    @JonB said in Who closes application on Escape?:

                    Just I'm sure the OP would have mentioned this vital piece of information if he were using a dialog

                    Haha. What I've learned from almost 3 years of being active here: Never trust OP's description of any issue :))


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    1
                    • D Offline
                      D Offline
                      django.Reinhard
                      wrote on 12 Nov 2021, 16:13 last edited by
                      #10

                      Thank you all for your attention!

                      ... and no! I'm not using or talking about any dialog.

                      I'm talking about QMainWindow.
                      A dialog closing on escape wouldn't have surprised me at all.

                      Just to be detailed and clear:
                      I have only QMainWindow open. This window is enriched by lots of dockables and several widgets have keyPressed overridden.

                      When I close the application by menu action or by titlebar button, a messagebox pops up to ask, whether I wonna close the app.

                      When I hit escape, the application shuts down that fast as if I would throw an exception. That has surprised me.
                      If I debug the app and an exception is thrown, the debugger tells me, that it had received a kill signal and I see the stack, so I can investigate what happened.
                      In this case, the debugger says nothing and there's no stacktrace.

                      The app has just terminated as intended.

                      I added a debug message to main after application::exec and that message is printed. So Escape terminates the eventloop and the main function ends normally.

                      J 1 Reply Last reply 12 Nov 2021, 16:59
                      0
                      • D django.Reinhard
                        12 Nov 2021, 16:13

                        Thank you all for your attention!

                        ... and no! I'm not using or talking about any dialog.

                        I'm talking about QMainWindow.
                        A dialog closing on escape wouldn't have surprised me at all.

                        Just to be detailed and clear:
                        I have only QMainWindow open. This window is enriched by lots of dockables and several widgets have keyPressed overridden.

                        When I close the application by menu action or by titlebar button, a messagebox pops up to ask, whether I wonna close the app.

                        When I hit escape, the application shuts down that fast as if I would throw an exception. That has surprised me.
                        If I debug the app and an exception is thrown, the debugger tells me, that it had received a kill signal and I see the stack, so I can investigate what happened.
                        In this case, the debugger says nothing and there's no stacktrace.

                        The app has just terminated as intended.

                        I added a debug message to main after application::exec and that message is printed. So Escape terminates the eventloop and the main function ends normally.

                        J Offline
                        J Offline
                        JonB
                        wrote on 12 Nov 2021, 16:59 last edited by JonB 11 Dec 2021, 16:59
                        #11

                        @django-Reinhard said in Who closes application on Escape?:

                        and several widgets have keyPressed overridden.

                        I can only think that somehow this is relevant. Remove all of this, or better still create a standalone 4-line program which just opens a QMainWindow and verify that Escape does not end the application. Then work back/forward from there, because the way you describe it sounds like the Qt app is indeed exiting "cleanly" if it returns from QApplication::exec().

                        D 1 Reply Last reply 13 Nov 2021, 03:43
                        0
                        • D django.Reinhard
                          12 Nov 2021, 13:58

                          Hi,

                          I accidently hit Escape and the application was closed as fast as possible.
                          I was astonished, as I did not code that feature.

                          And as I don't want that feature, I tried to find the source of it.
                          Adding keyPressEvent to MainWindow did not work.
                          So I started Application in debugger and put a breakpoint at QApplication::event() but debugger did not stop at Escape.

                          According Qt documentation of QKeySequence there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.

                          Debugger just says that application has finished with exit-code 0.

                          How can I find out, who is responsible for closing application?

                          P Offline
                          P Offline
                          Pl45m4
                          wrote on 12 Nov 2021, 17:58 last edited by
                          #12

                          @django-Reinhard said in Who closes application on Escape?:

                          Debugger just says that application has finished with exit-code 0.

                          A crash would not result in exit code 0.
                          Probably there is something wrong with your keyHandler


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          0
                          • J JonB
                            12 Nov 2021, 16:59

                            @django-Reinhard said in Who closes application on Escape?:

                            and several widgets have keyPressed overridden.

                            I can only think that somehow this is relevant. Remove all of this, or better still create a standalone 4-line program which just opens a QMainWindow and verify that Escape does not end the application. Then work back/forward from there, because the way you describe it sounds like the Qt app is indeed exiting "cleanly" if it returns from QApplication::exec().

                            D Offline
                            D Offline
                            django.Reinhard
                            wrote on 13 Nov 2021, 03:43 last edited by
                            #13

                            Hi,

                            thanks to your numerous "Qt won't do that" it was easy to me to find the culprit.

                            @JonB said in Who closes application on Escape?:

                            I can only think that somehow this is relevant.

                            You're right.
                            I use an opencascade widget, which I didn't spend much time for investigation. I just used it as is. And that widget killed the app at Escape key press.

                            Anyway - with this lesson I learned a lot about event-handling in Qt.

                            1 Reply Last reply
                            2

                            9/13

                            12 Nov 2021, 14:53

                            • Login

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