Separate QML files
I want to Separate my qml files
from main.qml
in the same qml.qrc
with different prefix.
Just like this:
- step1: Create new project test and Add prefix myQMLFiles
- step2: Add new QML file to qml.qrc Prefix: /myQMLFiles(in new folder testFile)
- step3: in
main.qml
:
import QtQuick 2.15
import QtQuick.Window 2.15
import "./testFile"
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
MyRect {
id: myRect_ID
}
}
- in
MyRect.qml
:
import QtQuick 2.15
Rectangle {
color: "pink"
width: 50
height: 50
}
-
in
qml.qrc
:
-
The error appeared when you run, but you build it without error.
-
WHY?
-
That’s the why:
-
import "./testFile"
-
must use qrc path!
-
import "qrc:/myQMLFiles/testFile"