Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] How can I capture Command+Q in a Qt Quick application?
QtWS25 Last Chance

[Solved] How can I capture Command+Q in a Qt Quick application?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k 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.
  • C Offline
    C Offline
    cscooper
    wrote on last edited by
    #1

    My application creates a QApplication, then a QQuickView, and then moves through the various screens by changing the "url" property of the QQuickView's rootObject().

    The application is supposed to appear standalone (the user doesn't need to know there's a Mac running it) so it has no menu and no way for the user to exit.

    However, on occasion there is a need to exit the application (and our users are allowed to do that), for which we normally just hit Command+Q. This does in fact exit the application, but also throws up a large panic screen about the program quitting unexpectedly.

    I've tried making my own classes deriving from QApplication and QQuickView and implementing a variety of signals and virtual overrides, but can't find anything that lets me jump in when a Command+Q gets hit and do some cleanup to avoid the panic screen.

    Any suggestions?

    Thanks,
    Chris

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

      Use this "flag":http://qt-project.org/doc/qt-5/qt.html#WidgetAttribute-enum:
      @
      Qt::WA_DeleteOnClose
      @

      on your top level window. This will invoke the destructor when the window is being closed and allow your app to properly clear the memory. Also, make sure you don't create your QGuiApplication instance on heap to avoid problems there.

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cscooper
        wrote on last edited by
        #3

        I'm confused ... my main window is a QQuickView which doesn't derive from QWidget, so I don't have any way to set a WidgetAttribute like WA_DeleteOnClose?

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

          Hm, ok. I have been fooled by your mention of QApplication, instead of QGuiApplication.

          In such case, I think you could connect application's aboutToClose() signal, with your window's close() slot. Or, alternatively, the deleteLater() slot.
          @
          QGuiApplication app(a, c);
          QQuickView myView;

          QObject::connect(&app, SIGNAL(aboutToClose(), &myView, SLOT(close()));

          myView.setSource(QUrl("blah blah.qml"));

          return app.exec();
          @

          If that still does not fix the problem, then we will think on how you can intercept the Command+Q.

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cscooper
            wrote on last edited by
            #5

            Since our application always runs full-screen, the only time it gets hidden is when it gets closed - so I subclassed QQuickView with my own MainView and wrote my own override hideEvent() that did the necessary shutdown.

            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