C++ 如何防止在加载程序中重新创建页面?
我正在Win/Android上开发一个Qt应用程序。我的问题很简单 当我的应用程序启动时,首先会有一个登录页面欢迎您。 如果要配置服务器设置,将在加载程序中打开ServerInfo.qml。登录页面和服务器信息加载在同一加载程序中。 我的问题是,当我关闭C++ 如何防止在加载程序中重新创建页面?,c++,qt,qml,C++,Qt,Qml,我正在Win/Android上开发一个Qt应用程序。我的问题很简单 当我的应用程序启动时,首先会有一个登录页面欢迎您。 如果要配置服务器设置,将在加载程序中打开ServerInfo.qml。登录页面和服务器信息加载在同一加载程序中。 我的问题是,当我关闭ServerInfo.qml,然后将loginpage.qml加载到加载程序时,加载程序会创建一个loginpage.qml的新实例。我不想再次创建页面 这是我的Qml代码: ApplicationWindow { id:mainwindo
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);
}
}
}
只需使用加载程序而不是加载程序
,当您将新表单推到顶部时,它将保持以前的“表单”处于活动状态,并且您可以始终来回移动
加载程序将加载单个元素,如果加载另一个元素,旧元素将被销毁,这是无法避免的 不过,您可以有多个装载机。习惯用法是:以后要加载的每个项目都有一个加载器。您可以有任意多个加载器,但仍然需要实现某种可见性和订单管理。这有点违背了目的,尤其是当你已经有了现成的问题的正确解决方案时。