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

Qt/Cocoa - QApplication::queryKeyboardModifiers() returns out of date values if application is not active

    XMLWordPrintable

Details

    • macOS

    Description

      QApplication::queryKeyboardModifiers() may return out-of-date values under Qt/Cocoa if the current application is not active. Internally this is due to an issue with the GetCurrentEventKeyModifiers() function that queryKeyboardModifiers() currently uses on Mac.

      See http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg01317.html and http://www.cocoabuilder.com/archive/cocoa/87836-getting-the-current-state-of-the-modifier-keys.html for more details.

      Sample app:

      #include <QtCore/QDebug>
      #include <QtGui/QApplication>
      #include <QtGui/QDragEnterEvent>
      #include <QtGui/QWidget>
      
      struct TestWidget : public QWidget
      {
      	virtual void dragEnterEvent(QDragEnterEvent* e) {
      		e->accept();
      	}
      
      	virtual void dragMoveEvent(QDragMoveEvent*) {
      		qDebug() << "active keyboard modifiers" << QApplication::queryKeyboardModifiers();
      	}
      };
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      
      	TestWidget* tw = new TestWidget;
      	tw->setAcceptDrops(true);
      	tw->resize(300,300);
      	tw->show();
      	
      	return app.exec();
      }
      

      Steps to reproduce:

      1. Build and run test app under Qt/Cocoa 4.8
      2. Bring up a Finder window and focus it, so that the test app's window loses focus
      3. Drag a file from Finder over the test app's window and whilst dragging the file around over the window, press and hold different modifier keys

      The terminal output should change to indicate the current modifier keys being held for each drag move event. The keyboard modifier information does not update however.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            robertknight Robert Knight
            Votes:
            10 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes