首页 > 代码库 > QML学习之Loader

QML学习之Loader

main.qml  
------------------------------------  
import QtQuick 1.0  
  
Item {  
    property bool isFirst : false;  
    width: 200  
    height: 200  
  
    Loader {  
        id: pageLoader  
    }  
  
    MouseArea {  
        anchors.fill: parent  
        onClicked: changePage();  
    }  
  
    function changePage() {  
        if(isFirst) {  
            pageLoader.source = "Page1.qml"  
        } else {  
            pageLoader.source = "Page2.qml"  
        }  
  
        isFirst = !isFirst;  
    }  
  
}  
  
  
Page1.qml  
-------------------------------------  
import QtQuick 1.0  
  
Rectangle {  
    width: 100  
    height: 62  
    Text {  
        anchors.centerIn: parent  
        text: "Page1 Test"  
    }  
}  
  
  
Page2.qml  
---------------------------------------  
import QtQuick 1.0  
  
Rectangle {  
    width: 100  
    height: 62  
    Text {  
        anchors.centerIn: parent  
        text: "Page1 Test"  
    }  
}

 

QML学习之Loader