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. QApplication::quit() does not trigger closeEvent() of the main window?
Qt 6.11 is out! See what's new in the release blog

QApplication::quit() does not trigger closeEvent() of the main window?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 699 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.
  • L Offline
    L Offline
    LiaoXuewei
    wrote on last edited by
    #1

    Hi, all:
    I have the same problem as the following:
    https://forum.qt.io/topic/93678/qapplication-quit-does-not-trigger-closeevent-of-the-main-window-by-design-or-bug

    Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.

    sierdzioS 1 Reply Last reply
    0
    • L LiaoXuewei

      Hi, all:
      I have the same problem as the following:
      https://forum.qt.io/topic/93678/qapplication-quit-does-not-trigger-closeevent-of-the-main-window-by-design-or-bug

      Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @LiaoXuewei said in QApplication::quit() does not trigger closeEvent() of the main window?:

      Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.

      It is not a bug. Reimplement closeEvent() and it will be triggered when the user attempts to close the application.

      It will not be triggered when your code attempts to quit the app. So, a solution is to use QWidget::close() instead of QApplication::quit() in your case.

      (Z(:^

      L 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @LiaoXuewei said in QApplication::quit() does not trigger closeEvent() of the main window?:

        Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.

        It is not a bug. Reimplement closeEvent() and it will be triggered when the user attempts to close the application.

        It will not be triggered when your code attempts to quit the app. So, a solution is to use QWidget::close() instead of QApplication::quit() in your case.

        L Offline
        L Offline
        LiaoXuewei
        wrote on last edited by
        #3

        @sierdzio Example, user close qt app by taskbar, but app cann't detect. Do you think it's normal?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LiaoXuewei
          wrote on last edited by
          #4

          Hi, all:
          I am sorry, i had made a mistake.
          I had test QApplication::quit() will trigger closeEvent() of the main window!
          I had wrote closeEvent in sub window before, so did not trigger!

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            OK, happy to see that it's solved :-)

            (Z(:^

            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