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. [SOLVED] Catch Cmd+Q
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Catch Cmd+Q

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.7k Views 1 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.
  • B Offline
    B Offline
    birmacher
    wrote on 14 Feb 2011, 10:53 last edited by
    #1

    Hi

    I'd like to catch Cmd+Q to prevent the application termination in some cases.
    I found this for win, but I'm not able to implement it under mac. Also didn't found any modifier for the command button like QT::ControlModifier.
    http://developer.qt.nokia.com/faq/answer/how_can_i_catch_altf4_in_my_qt_application

    Tried to accept the event, without checking the modifier, but no luck with that also

    Can somebody help me out?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jorj
      wrote on 14 Feb 2011, 13:26 last edited by
      #2

      i think you can use Qt::MetaModifier as the windows or cmd key.

      other than that the above should work, you could also reimplement

      @virtual bool QObject::event( QEvent * e );@

      and catch it there, but either method should work, it depends where you are trying to catch the key from.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frankcyblogic.de
        wrote on 14 Feb 2011, 14:02 last edited by
        #3

        @birmacher: The correct way to do this is to overload QWidget::closeEvent(). Take a look at the documentation for more "details":http://doc.troll.no/4.7/qwidget.html#closeEvent . Actually the FAQ is referring to another use-case than yours. It only refers to a hack which is meant to allow defining other than application termination logic on Alt+F4.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          birmacher
          wrote on 14 Feb 2011, 19:26 last edited by
          #4

          Thanks for the tips. I did override the closeEvent, with no success.
          Finally it turned out that I was catching the Qt::Close event also. Removing it did the trick:)

          Thanks for your help!

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cdietz
            wrote on 28 Nov 2017, 08:38 last edited by cdietz
            #5

            6 years later, this is basically still the correct answer; when using class QGuiApplication without widgets, this is the way to go:

            bool MyDerivedFromQGuiApplication::event( QEvent* event_in )
            {
                if ( event_in->type() == QEvent::Close )
                {
                    event_in->ignore();
                    // INSERT: custom handling
                    return true;
                }
                return QGuiApplication::event( event_in );
            }
            
            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