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;
}
}
}
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?
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…