简体   繁体   English

应用程序退出后退按钮在android qtquick中单击

[英]App exits on back button click in android qtquick

I am developing an app which will run firstly on Android. 我正在开发一个将首先在Android上运行的应用程序。 However, I have an issue with back button: each time it is tapped the application quits. 但是,我对后退按钮有一个问题:每次点击该应用程序都会退出。 I don't want this behaviour. 我不要这种行为。 I have checked a lot of approaches and I've tried to implement some code but nothing worked. 我检查了很多方法,并尝试实现一些代码,但没有任何效果。

Here is my code: 这是我的代码:

Item {
    id: student_home_page;
    focus: true

    // ///////////////////////////////////////////////////////////////

    Keys.onReleased: {
        console.log("TEST for Back ");
        if (event.key == Qt.Key_Back) {
            console.log("BAck Button HAndled");
            event.accepted = true;
        }
    }
}

When I click back button after reaching this page, it does not print anything on console as it is not going inside 当我到达此页面后单击“后退”按钮时,它不会在控制台上打印任何内容,因为它不会进入内部

I only get this message on console of Qt Creator: 我仅在Qt Creator的控制台上收到此消息:

/uniActivity(15431): onStop / uniActivity(15431):onStop
I/AndroidRuntime(15431): VM exiting with result code 0, cleanup skipped. I / AndroidRuntime(15431):VM退出,结果代码为0,清除已跳过。

Any idea why it is not handling this key event or not any at all inside? 知道为什么它不处理此关键事件还是内部根本不处理吗?

您应该处理StackView本身内部的后退按钮,而不是子页面,请在此处查看我的答案

Maybe this could be useful for you. 也许这对您有用。 Try to override the activity onBackPressed() method: 尝试覆盖活动onBackPressed()方法:

@Override
public void onBackPressed() {
    // Do something or call finish()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM