Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-59782

Qt.quit() exits immediately without sending a QCloseEvent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.0
    • 5.9.0 Alpha
    • None

    Description

      It's connected directly to QCoreApplication::quit() in QQmlApplicationEngine.

      This is inconsistent because if you declare a Shortcut:

              Shortcut {
                  sequence: StandardKey.Quit
                  onActivated: {
                      console.log("quitting now")
                      context: Qt.ApplicationShortcut
                      Qt.quit()
                  }
              }
      

      that's useful on most platforms, but on macOS your application has a Quit menu item independently. And that will send a QCloseEvent. The intention after we fix QTBUG-33235 is that any window should be able to veto the closing by rejecting the close event, in a QML onClosing handler. So the consistent cross-platform way to prompt "are you sure" in QML, to save files or whatever, is to implement Window.onClosing(). (You could do that in the Shortcut.onActivated() handler, but it won't work on macOS.) So if you have done that, and you also create a quit Shortcut for non-mac platforms, it needs to end up exiting in the same way, whether you get there via the Shortcut or via the menu item.

      This will be consistent with widget-based applications: on macOS if you create a Quit menu item, it will be functional, and your widget windows can handle the close event and veto the closing. If you don't create the Quit menu item, you will still get one automatically, and it will work the same way as if you had created it.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-59782
          # Subject Branch Project Status CR V

          Activity

            People

              vestbo Tor Arne Vestbø
              srutledg Shawn Rutledge
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews