当我关闭弹出窗口然后单击手机上的后退按钮时,我的应用程序在 qml 中关闭
When I close the popup and then click the back button on my mobile then my app gets close in qml
Page{
id: app
Popup {
id: popup1
background: Rectangle {
implicitWidth: 400
implicitHeight: 200
Row{
topPadding: 40
leftPadding: 10
Text {
id: warning
text: qsTr("Are you sure you want to exit the App ?")
}
}
Row{
topPadding: 100
leftPadding: 60
Button {
id: yes_btn
text: qsTr("YES")
onClicked:
{
Qt.quit();
}
}
Button {
id: no_btn
text: qsTr("NO")
onClicked:
{
popup1.close();
}
}
}
}
}
Keys.onBackPressed: {
popup1.open();
}
}
在后退按钮上按下我的 phone 弹出窗口 1 打开,当我关闭弹出窗口并再次按下后退按钮时,我的应用程序没有打开弹出窗口而是关闭了。如何预防?
一个可能感兴趣的解决方案您正在使用每次按下后退按钮时发送的 onClosing
信号。
onClosing: {
close.accepted = false
if (popup1.opened)
popup1.close()
else
popup1.open()
}
此代码应使您的弹出窗口在按下后退按钮时打开,并在打开时关闭。
Page{
id: app
Popup {
id: popup1
background: Rectangle {
implicitWidth: 400
implicitHeight: 200
Row{
topPadding: 40
leftPadding: 10
Text {
id: warning
text: qsTr("Are you sure you want to exit the App ?")
}
}
Row{
topPadding: 100
leftPadding: 60
Button {
id: yes_btn
text: qsTr("YES")
onClicked:
{
Qt.quit();
}
}
Button {
id: no_btn
text: qsTr("NO")
onClicked:
{
popup1.close();
}
}
}
}
}
Keys.onBackPressed: {
popup1.open();
}
}
在后退按钮上按下我的 phone 弹出窗口 1 打开,当我关闭弹出窗口并再次按下后退按钮时,我的应用程序没有打开弹出窗口而是关闭了。如何预防?
一个可能感兴趣的解决方案您正在使用每次按下后退按钮时发送的 onClosing
信号。
onClosing: {
close.accepted = false
if (popup1.opened)
popup1.close()
else
popup1.open()
}
此代码应使您的弹出窗口在按下后退按钮时打开,并在打开时关闭。