1
私は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);
}
}
}
ただし、複数のローダーを使用することはできます。イディオムは、後でロードするアイテムごとに1つのローダーです。 –
あなたはあなたが好きな数だけ持つことができますが、あなたはまだ何らかの可視性と注文管理を実装しなければなりません。それは、特にあなたがすでに問題の正しい解決策を箱の外に持っているとき、その目的を破るものです。 – dtech