How to import a QML file from a different Directory
-
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
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. -
@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)