I want to import my custom QML type MyType from subdirectory mytypes into my main.qml file. Which is also in the same directory with the mytypes folder. I used this documentation page as reference. http://doc.qt.io/qt-5/qtqml-syntax-directoryimports.html
I use it as follows:
import "mytypes"
MyType {
}
In code, MyType is recognized and highlighted as usual. However, when I run the application, I get the following error:
qrc:/main.qml:5:1: "mytypes": no such directory
And my .qrc file looks like that:
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
<qresource prefix="/mytypes">
<file>mytypes/MyType.qml</file>
</qresource>
</RCC>
So where is the error? Should I also make some changes in the .pro file?
The qrc file
says
mytypes/MyType.qmlis under the prefix/mytypes. Therefore, the import statement inmain.qmlshould include that prefix:Or, remove
/mytypesprefix and movemytypes/MyType.qmlunder/prefix in qrc file:and
main.qmlcan import the type directly: