2016-04-01 14 views
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); 
     } 


    } 


    } 

答えて

2

だけではなく、LoaderStackViewを使用し、あなたが一番上に新しいものをプッシュすると、それは生きている、以前の「フォーム」を維持する、とあなたは常に前後に行くことができます。

ローダーは1つの要素を読み込みますが、別の要素を読み込んだ場合は古い要素が破棄されますが、その周りには方法はありません。

+0

ただし、複数のローダーを使用することはできます。イディオムは、後でロードするアイテムごとに1つのローダーです。 –

+0

あなたはあなたが好きな数だけ持つことができますが、あなたはまだ何らかの可視性と注文管理を実装しなければなりません。それは、特にあなたがすでに問題の正しい解決策を箱の外に持っているとき、その目的を破るものです。 – dtech

関連する問題