Qt
  1. Qt
  2. QTBUG-59670

Popup without explicit closePolicy closes App on Android BACK key

    Details

    • Commits:
      49163ca689562a4a000490fb137e5c9533684471

      Description

      If no explicit closePolicy is set, hitting the BACK Key on Android quits the APP. There's no way to catch the BACK Key.
      Qt 5.7 and QQC2.0 works well - it happens with new default closePolicy in 5.8
      Here's to test:

      import QtQuick 2.7
      import QtQuick.Controls 2.1
      import QtQuick.Layouts 1.3
      import QtQuick.Controls.Material 2.1
      
      ApplicationWindow {
          id: window
          width: 640
          height: 480
          visible: true
      
          Page {
              id: thePage
              anchors.fill: parent
      
              Label {
                  id: theLabel
                  text: "Close Policy Test"
                  anchors.centerIn: parent
              }
      
              Button {
                  anchors.top: theLabel.bottom
                  text: "Popup BACK KEy Test"
                  onClicked: {
                      thePopup.open()
                  }
              }
      
      
              Popup {
                  id: thePopup
                  // closePolicy: Popup.CloseOnPressOutside
                  width: 200
                  height: 200
                  Label {
                      text: "Press BACK Key"
                  }
              }
      
              Keys.onBackPressed: {
                  event.accepted = true
                  theLabel.text = "BACK KEY consumed"
              }
      
      
          } // page
      }
      
      
      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

        Hide
        Ekkehard added a comment -

        also there's a problem with modal Popup and closePolicy Popup.NoAutoClose

        modal Popup should block the Android BACK Key
        But the Key goes thru to the Keys.onBackPressed

        have not tested yet what happens on Windows10 mobile BACK Key in both cases

        Show
        Ekkehard added a comment - also there's a problem with modal Popup and closePolicy Popup.NoAutoClose modal Popup should block the Android BACK Key But the Key goes thru to the Keys.onBackPressed have not tested yet what happens on Windows10 mobile BACK Key in both cases
        Hide
        Ekkehard added a comment -
        Show
        Ekkehard added a comment - blogged about the problems and workarounds: https://appbus.wordpress.com/2017/03/04/mostly-harmless-update-qt-5-7-0-qt-5-8-0/
        Hide
        J-P Nurmi added a comment -

        Same issue with QML Shortcut from Qt Quick core:

        import QtQuick 2.7
        import QtQuick.Window 2.2
        import QtQuick.Controls 2.0
        
        Window {
            id: window
            width: 360
            height: 360
            visible: true
        
            CheckBox {
                id: checkbox
                checked: true
                text: "BACK shortcut enabled"
                anchors.centerIn: parent
            }
        
            Shortcut {
                sequence: "Back"
                enabled: checkbox.checked
                onActivated: window.contentItem.ToolTip.show("BACK shortcut activated", 2500)
            }
        }
        
        Show
        J-P Nurmi added a comment - Same issue with QML Shortcut from Qt Quick core: import QtQuick 2.7 import QtQuick.Window 2.2 import QtQuick.Controls 2.0 Window { id: window width: 360 height: 360 visible: true CheckBox { id: checkbox checked: true text: "BACK shortcut enabled" anchors.centerIn: parent } Shortcut { sequence: "Back" enabled: checkbox.checked onActivated: window.contentItem.ToolTip.show( "BACK shortcut activated" , 2500) } }
        Hide
        J-P Nurmi added a comment -

        The bug is in QGuiApplicationPrivate::processKeyEvent(). Fix proposal https://codereview.qt-project.org/#/c/190781/

            QGuiApplication: fix Menu and Back key handling
            
            Don't quit on Back key release when Back shortcut was accepted and
            likewise for the Menu key, don't trigger the platform menubar if Menu
            shortcut was accepted.
        
        Show
        J-P Nurmi added a comment - The bug is in QGuiApplicationPrivate::processKeyEvent(). Fix proposal https://codereview.qt-project.org/#/c/190781/ QGuiApplication: fix Menu and Back key handling Don't quit on Back key release when Back shortcut was accepted and likewise for the Menu key, don't trigger the platform menubar if Menu shortcut was accepted.
        Hide
        J-P Nurmi added a comment -

        The problem was Android-specific. Qt for Android has special handling for the Back-key. If Back-press is not accepted, Back-release quits the app. However, it did not consider that Back-press can trigger a Back-shortcut, which in turn can be accepted. Therefore it quit the app, because it thought that Back-press had not been accepted even though a Back-shortcut had been accepted. The problem has been fixed in qtbase: https://codereview.qt-project.org/#/c/190781/

        Show
        J-P Nurmi added a comment - The problem was Android-specific. Qt for Android has special handling for the Back-key. If Back-press is not accepted, Back-release quits the app. However, it did not consider that Back-press can trigger a Back-shortcut, which in turn can be accepted. Therefore it quit the app, because it thought that Back-press had not been accepted even though a Back-shortcut had been accepted. The problem has been fixed in qtbase: https://codereview.qt-project.org/#/c/190781/

          People

          • Assignee:
            J-P Nurmi
            Reporter:
            Ekkehard
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes