QML多页面的创建与返回

来源:互联网 发布:好布业软件 编辑:程序博客网 时间:2024/05/10 12:54

创建一个动态页面

var object=Qt.createComponent("lightMoshi.qml").createObject(lightpage)

lightMoshi.qml是要跳转的页面,lightpage是父页

页面的销毁

lightpage.destroy()

多页面的销毁与跳转

parlopage.qml

var object=Qt.createComponent("lightMoshi.qml").createObject(parlopage)

                      object.title = "客厅"
lightMoshi.qml

 propertyaliastitle:titleText.text

Text {

        id: titleText
        color: "red"
    }

onClicked: {

      lightpage1.destroy()
     if(titleText.text == "客厅")
      parlopage.destroy()
       else
       bedroompage.destroy()
}
这种跳转界面上会显示自己取名的标题
第二种不带标题的跳转
lightMoshi.qml
property alias title:lightpage1.objectName
 
onClicked: {
       lightpage1.destroy()
       if(lightpage1.objectName == "客厅")
        parlopage.destroy()
        else
         bedroompage.destroy()
 }
 
多次试验后发现上述方法只适合两个页面之间切换,当多个页面的时候越来越麻烦,后来找到了另外一种删除页面的方法
onClicked: {
             lightpage2.destroy()
             lightpage2.parent.destroy()
             lightpage2.parent.parent.destroy()
          }
原创粉丝点击