即使焦点设置为 true,后退键导航也不起作用

Back key navigation doesn't work even though focus is set to true

在我的 Qt Android 应用程序中,我将一个项目从菜单推送到 StackView:

import QtQuick 2.0
import QtQuick.Controls 1.0

ApplicationWindow
{
    menuBar: MenuBar
    {
        Menu
        {
            title: qsTr("Menu")
            MenuItem
            {
                text: qsTr("Push page")
                onTriggered: stackView.push("qrc:/qml/SecondPage.qml")
            }
        }
    }

    StackView
    {
        id: stackView
        anchors.fill: parent
        // Implements back key navigation
        focus: true

        initialItem: FirstPage
        {
            width: parent.width
            height: parent.height
        }
    }
}

SecondPage.qml:

import QtQuick 2.0
import QtQuick.Controls 1.0

Item
{
    width: parent.width
    height: parent.height
    // focus: true

    Keys.onBackPressed: stackView.pop()

    Label
    {
        anchors.centerIn: parent
        text:  "Some text"
        font.pointSize: 32
        color: "gray"
    }
}

尽管如此,返回键退出了整个应用程序。我尝试将 focus: true 添加到它被注释掉的地方,并在 Keys.onBackPressed 中调用 event.accepted = true。为什么后退键被忽略了?

我应该将 pop 语句放入 StackView 本身,而不是子页面:

StackView
{
    id: stackView
    anchors.fill: parent
    // Implements back key navigation
    focus: true

    initialItem: FirstPage
    {
        width: parent.width
        height: parent.height
    }

    Keys.onBackPressed: pop()
}