How to import a QML file from a different Directory
-
wrote on 7 May 2019, 11:40 last edited by
I'am trying to use a qml in a different directory than my project directory.
The QT editor is recognises the qml. and Build is successful.
During runtime, there is an error message stating it cannot find the file.Directory Flow
Test
- test.qml
MainApp
-main.qml
-mainApp.pro
-main.cppIn Main.qml, I am importing test.qml as
import "../Test/" , the path is not being recognised during runtime.Can you please suggest me a solution for this.?
-
I'am trying to use a qml in a different directory than my project directory.
The QT editor is recognises the qml. and Build is successful.
During runtime, there is an error message stating it cannot find the file.Directory Flow
Test
- test.qml
MainApp
-main.qml
-mainApp.pro
-main.cppIn Main.qml, I am importing test.qml as
import "../Test/" , the path is not being recognised during runtime.Can you please suggest me a solution for this.?
Moderatorswrote on 7 May 2019, 11:58 last edited by raven-worx 5 Jul 2019, 12:10@Anita
the import url is resovled from the base url the qml file was loaded from.
Are we talking about qrc or file paths here?
If MainApp/main.qml was loaded via qrc, then there Test/test.qml must also be available within qrc. -
I'am trying to use a qml in a different directory than my project directory.
The QT editor is recognises the qml. and Build is successful.
During runtime, there is an error message stating it cannot find the file.Directory Flow
Test
- test.qml
MainApp
-main.qml
-mainApp.pro
-main.cppIn Main.qml, I am importing test.qml as
import "../Test/" , the path is not being recognised during runtime.Can you please suggest me a solution for this.?
@Anita
you can take a look at my struggle with this:
https://forum.qt.io/topic/98165/import-with-relative-pathCould be helpful
the actual correct way to handle this correctly would be via your own qml module:
http://doc.qt.io/qt-5/qtqml-modules-topic.htmlor as a plugin:
http://doc.qt.io/qt-5/qqmlextensionplugin.htmlBut I don't know more about it. That's as far as I got before something else came along with more priority x)
-
wrote on 13 Jun 2019, 10:56 last edited by
You can use alias in the qrc file to have all the files in a single directory so that you can use them directly or else you can import the qml stuffs by using import statement (make sure you give the correct path of the file)
-
wrote on 20 Jun 2019, 05:37 last edited by
@raven-worx , @J-Hilk
Thanks For the solution. It is working by importing the qml as "qrc:/../Test/ in main.qml.