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

QInputEvent methods are not virtual

    XMLWordPrintable

Details

    Description

      If you store a QKeyEvent just as QInputEvent, which is possible because QKeyEvent inherit from QInputEvent, modifiers are broken, because modifier method is not virtual.

      Example (pressing left control modifier)

      #include <QApplication>
      #include <QDebug>
      #include <QKeyEvent>
      #include <QMainWindow>
      
      class TestWindow : public QMainWindow
      {
      protected:
      	void keyPressEvent(QKeyEvent* event) override
      	{
      		QInputEvent* inputEvent = event;
      		//returns true
      		qDebug() << event->modifiers().testFlag(Qt::ControlModifier);
      		//returns false
      		qDebug() << inputEvent->modifiers().testFlag(Qt::ControlModifier);
      	}
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      	TestWindow w;
          w.show();
      
          return a.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sletta Gunnar Sletta
            EliteScience Heiko Thiel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes