第一章 基础设置

(3)qml文件导入

  1. Screen01.qml与Main.qml位于同一级目录,在Main.qml导入方法如下:

import QtQuick 
import QtQuick.Controls 

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Demo")

    // 加载 Screen01.qml
    Loader {
        id: screenLoader
        source: "Screen01.qml" // 直接引用同目录下的文件
        anchors.fill: parent
    }
}
  1. Screen01.qml与Main.qml位于非同一级目录,Screen01.qml在screens文件夹下,在Main.qml导入方法如下:

Cmakelists.txt

Main.qml

最后更新于