Importing qml
-
Hi,
I am having problem with importing of a qml file in another file.My folder structure is as follows:
Project
-Build
- SourceProject
-main.qml
-qml.qrc
-ButtonFile.qml
-Source
-Widgets
-PopupWidget
-Popup.qmlI want to import ButtonFile.qml in my Popup.qml,
qml.qrc file is as follows:
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>ButtonFile.qml</file>
<file>../../Source/Widgets/PopupWidget/Popup.qml</file>
</qresource>So having this as folder structure how do i import ButtonFile.qml in the file Popup.qml?
-
Perhaps this will work:
import ":/" // or import "qrc://" // or import "../../.." // some code ButtonFile { }
Please show your structure in some other way the current list is quite hard to understand.
-
@sierdzio
I have 2 main folder in my Project : Build and Source.
The Build Folder Consists of a Folder SourceProject .which contains the files main.qml,qml.qrc, ButtonFile.qml.
The Source Folder consists of a Folder named Widgets which contains another folder named PopUpWidgets, and PopupWidgets Contains Popup.qml.I tried all the three import statements, during runtime it gives an error "no such directory" for all the three import statements.
-
I tried this , during runtime i got an error:
"../../Build/SourceProject/": no such directoryI have tried import "qrc:/../../../Build/SourceProject/" as well im getting the same error.
I changed the path of the buttonFile.qml in qrc file from <file>ButtonWidget.qml</file> to <file>../../Build/SourceProject/ButtonWidget.qml</file> and imported the qml as "qrc:/../../../Build/SourceProject/" it worked.
Is it necessary for the import path that we mention in the file and the path in qml.qrc file be the same?
-
@Anita said in Importing qml:
Is it necessary for the import path that we mention in the file and the path in qml.qrc file be the same?
Yes, unless you create an alias, like this:
<file alias="Some_name.qml">long/path/to/file/File.qml</file>
The alias can even change the file name and extension (or have no extension at all - but not sure if QML engine will understand it).