Android的后退按钮preSS不会触发keys.onreleased QML [英] Android back button press doesn't trigger keys.onreleased qml

查看:352
本文介绍了Android的后退按钮preSS不会触发keys.onreleased QML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造的Qt5.3和Qtquick2.1程序。我试图捕捉回来的Andr​​oid按键preSS在我使用Keys.onReleased code。但是,事件没有得到触发。此外,我已经设置的项目重点为true。但仍然没有成功。这里是code样品

I am creating a program in Qt5.3 and Qtquick2.1. I am trying to capture back button press on android in my code using Keys.onReleased. But that event is not getting triggered. Also I have set the item focus to true. But still no success. Here is the code sample

import QtQuick 2.1
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1

Rectangle
{
    id: main2
    focus: true
    width: Screen.Width
    height: Screen.Height
    Keys.enabled: true
    Keys.priority: Keys.BeforeItem

    property string load_page: ""
    signal deskConnected()

    Loader{
        id: pageloader
        anchors.fill: parent
        source: "qrc:/qml/resources/Firstpage.qml"
    }

    onDeskConnected: {
         pageloader.item.onDeskConnected()
    }

    function loadPatwin(){
        pageloader.source = "qrc:/qml/resources/Secondpage.qml";
    }

    Keys.onReleased: {
        console.log("back");
        if (event.key === Qt.Key_Back) {
            event.accepted=true;
        }
    }
}

下面lo​​adPatwin是被调用的pressing这是在其他一些QML定义了一个按钮的功能。并加载一个新的QML。但在那之后,当我pressing在Android上的后退按钮,应用程序被关闭,它不打印,甚至背在日志中。任何建议我在做什么错在这里?

Here loadPatwin is the function which gets called on pressing a button which is defined in some other qml. And loads a new qml. But after that when I am pressing the back button on android, the app gets closed and it doesn't print even "back" in the logs. Any suggestions what I am doing wrong here?

在此先感谢。

推荐答案

这对我的作品中加入forceActiveFocus()后,该项目已完成加载。

It works for me by adding "forceActiveFocus()" after the item has completed loading.

在你的榜样,我希望把它放在开头。像这样的:

In your example I would put it at the beginning. Like this:

Rectangle
{
    id: main2
    focus: true

    Component.onCompleted: {
        main2.forceActiveFocus()
    }

这篇关于Android的后退按钮preSS不会触发keys.onreleased QML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆