gpt4 book ai didi

c++ - 如何防止在加载程序中重新创建页面?

转载 作者:行者123 更新时间:2023-11-30 03:43:05 25 4
gpt4 key购买 nike

我正在 Win/Android 上开发 Qt 应用程序。我的问题很简单。

当我的应用程序启动时,首先会出现一个登录页面欢迎您。如果要配置服务器设置,ServerInfo.qml 在加载程序中打开。登录页面和 ServerInfo 在同一个加载器中加载。我的问题是,当我关闭 ServerInfo.qml,然后将 loginpage.qml 加载到加载器时,加载器会创建一个新的 loginpage.qml 实例.我不希望再次创建该页面。

这是我的 Qml 代码:

ApplicationWindow  {
id:mainwindow
visible: true
width: 600
height: 800
x: Screen.width / 2 - width / 2
y: Screen.height / 2 - height / 2
menuBar:MenuBar{
Menu {
title:"Edit"
MenuItem {
text:"Sunucu Ayarları"
onTriggered: {
loader.source="ServerConfig.qml"
loader.anchors.centerIn=main
}
}
MenuItem {
text:"Çıkış"
onTriggered: {
Qt.quit();
}
}
}
}
Connections {
ignoreUnknownSignals: true
target: process
onProcessstart: {
busyrec.visible=true;
busyloader.item.busytext=text;
busyloader.item.busyrunnig=true;
}
onProcessstop: {
busyloader.item.busytext=text;
busyloader.item.busyrunnig=false;
busyloader.item.busytextcolor="blue"
}
Component.onCompleted: {
// process.onSuccesLogin();
//TaskResultm.taskresult.Malzemeler.push
console.log(TaskResultm.taskresult.serilaze());
}
}

Column {
anchors.fill: parent
Rectangle {
id:busyrec
width: parent.width
height: (parent.height/10)
visible:true
color:"green"
Loader {
id:busyloader
source:"BusyIndicator.qml"
anchors.fill: parent
}

Connections {
ignoreUnknownSignals: true
}
}

Rectangle {
id: main
// anchors.fill: parent
width: parent.width
height: (parent.height/10)*9
Loader {
id:loader
source: "LoginPage.qml"
anchors.centerIn:parent
focus:true
property bool valid: item !== null
}

Connections {
ignoreUnknownSignals: true
target: loader.valid? loader.item : null

onDirecttomainpage:{
// process.getWorkOrderList();
busyloader.item.switenabled=true;
busyloader.item.switopacity=1;
loader.anchors.fill=main;
loader.source="TaskNavigationMainScreen.qml";

}
onServerinfopageclose: {


loader.source="LoginPage.qml";
loader.anchors.centerIn=main;

}
}


}

}

onClosing: {

if(Qt.platform.os=="android") {

if(loader.item!==null)
{
if(loader.item.objectName==="tasknavigationmain")
if(loader.item.zemin===0)
close.accepted=true;
else
close.accepted=false;
}
}
else if (Qt.platform.os=="windows")
{
Qt.quit();
//if(loader.item!==null)
// if(loader.item.objectName==="tasknavigationmain")
// console.log(loader.item.stackViewItem.depth);
}


}


}

最佳答案

只需使用 StackView而不是 Loader,它会在您将新的“表单”推到顶部时保持以前的“表单”处于事件状态,并且您可以随时来回切换。

加载器将加载单个元素,如果加载另一个元素,旧元素将被销毁,这是没有办法解决的。

关于c++ - 如何防止在加载程序中重新创建页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36352603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com