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

Multiple events for one android back click

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.5.0
    • 5.4.1
    • QPA
    • None
    • Qt 5.4.1, arm7, Android
    • Android
    • 4f8171998378f3e0f345b2b417afbfc9ad9738f0

    Description

      Get too many press/release events when clicking only once on the android back-key. Building for arm7/android.

      Motivation is to make a pressAndHold event for the back-key, then I found this issue. A test example is attached.

      First, creating a default qt/cpp project. Installing an event-filter to the main.cpp/app to filter away auto-repeat events when holding down a key.

      When printing out what happens, I see this when pressing down (and holding down for some seconds) and then releases the Android back-key. The log below is both from the event-filter and from the application, see attached source code for details. Note that the application get two press events and one release event.

      Application snippet:

      main.qml
      FocusScope {
                  focus: true
      
                  Keys.onPressed: {
                      event.accepted = true
                      console.debug("Application onPressed")
                  }
                  Keys.onReleased: {
                      event.accepted = true
                      console.debug("Application onReleased")
                  }
              }
      

      Eventfilter snippet:

      keyeventfilter.cpp
      bool KeyEventFilter::eventFilter(QObject *obj, QEvent *e){
          if(!(e->type() == QEvent::KeyPress ||
                  (e->type() == QEvent::KeyRelease)))
              return QObject::eventFilter(obj, e);
      
          QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);
          if(keyEvent->isAutoRepeat())
          {
              e->ignore();
              return true;
          }
          qDebug() << "Filtered event: " << keyEvent->key() << e->type() << keyEvent->timestamp();
          return QObject::eventFilter(obj, e);
      }
      
      

      Bug: I would have assumed only one press event to the application.

      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 6 21383
      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 6 21383
      D/libAndroidBackTest.so(31135): qrc:/main.qml:32 (onPressed): qml: Application onPressed
      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 6 21885
      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 6 21885
      D/libAndroidBackTest.so(31135): qrc:/main.qml:32 (onPressed): qml: Application onPressed
      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 7 23292
      D/libAndroidBackTest.so(31135): ..\AndroidBackTest\keyeventfilter.cpp:22 (virtual bool KeyEventFilter::eventFilter(QObject*, QEvent*)): Filtered event: 16777313 7 23292
      D/libAndroidBackTest.so(31135): qrc:/main.qml:36 (onReleased): qml: Application onReleased

      Attachments

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

        Activity

          People

            andysh Andy Shaw
            quicky Dag Vegar Tveitå
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes