Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Back button click Android not registered in Qt Webview

    Mobile and Embedded
    qt5.10 qml android html
    1
    1
    707
    Loading More Posts
    • 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.
    • R
      Ramonn last edited by

      I am creating a small Android application in Qt 5.10. The application consists of a main.qml that holds a Qt StackView. In this StackView one Qt Flickable page is defined with a button on it to navigate to a new page, which is a Qt WebView. After navigation, this WebView will load a local HTML page. But when I hit the Android back button on the second page the app will not navigate back to the first one. See the code below for more information.

      main.qml

      import QtQuick 2.10
      import QtQuick.Controls 2.2
      
      ApplicationWindow {
          id: appWindow
          visible: true
      
          StackView {
              id: navPane
              anchors.fill: parent
              initialItem: pageOne
      
              Keys.onBackPressed: {
                  popOnePage()
              }
      
              function popOnePage() {
                  if(navPane.depth == 1)
                      return
                  pop()
              }
      
              function pushOnePage(pageComponent) {
                  push(pageComponent)
              }
          }
      
          Component {
              id: pageOne
              PageOne {}
          }
      
          Component {
              id: pageTwo
              PageTwo {}
          }
      }
      
      

      PageOne.qml

      import QtQuick 2.10
      import QtQuick.Controls 2.2
      
      Flickable {
      
          Button {
              text: "Go to page 2"
              anchors.centerIn: parent
      
              onClicked: {
                  navPane.pushOnePage(pageTwo)
              }
          }
      }
      

      PageTwo.qml

      import QtQuick 2.10
      import QtWebView 1.1
      
      WebView {
          id: webView
          url: initialUrl //link to local HTML file
      }
      

      After some debugging I found out that the Keys.onBackPressed signal is never received. But when I use a Flickable instead of a WebView the signal will be received and the navigation works as expected. Can someone tell me if it is possible to receive this signal while using a WebView or maybe tell me what I am doing wrong? It will also do for me if there exists another component that can work with HTML. Any help would be greatly appreciated!

      1 Reply Last reply Reply Quote 0
      • First post
        Last post