Go back screen when back button is pressed on android does not work, app quits

  • I am trying to implement a behavior on android when the back-button is pressed. So I do this in main.qml (in the ApplicationWindow):

     onClosing: {
            if (Qt.platform.os == "android") {
                console.log("Testing for andorid")
                if (stackView.depth > 1) {
                    close.accepted = true;
                } else { Qt.quit(); }

    If I press the back button on android, this is the output:

    D/Aerger  ( 5712): qrc:/main.qml:66 (onClosing): qml: Testing
    D/Aerger  ( 5712): qrc:/main.qml:68 (onClosing): qml: Testing for andorid
    D/Aerger  ( 5712): qrc:/main.qml:71 (onClosing): qml: Closing
    I/ActivityManager(  561): Process de.goodpoint_hd.aerger (pid 5712) has died

    AND the application quits! From the output, I can see that "close.accepted = true" is called. Should that not prevent the event from having an effect?

    What am I doing wrong?

  • Not sure if you resolved your issue or not, but a 'solution' was posted here

  • Hey,you can go to the previous screen using back button on your Android Phone
    by using this code.

    Keys.onReleased: {
    if (event.key === Qt.Key_Back) {
    console.log("Back button of phone pressed")
    event.accepted = true

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.