QML resource management in 5.9
I am migrating my project from Qt 5.5 to Qt 5.9.
the project is organized as follows:
* proj root * data * quick * uiMain.qml * otherComponent.qml * ... * prj * myApp * project * myApp.pro
The major problem is the following: I used to run the application in working dir
proj rootand load my qml source like this:
uiMainused to get loaded and could simply use
otherComponentand all other qml types in the same subdirectory.
As of Qt 5.9, the call to
setSource()triggers an assertion fail because relative file paths are not allowed anymore. I have tried to migrate everything to Resources and now I'm loading the main QML file like this:
and in the
<qresource lang="qml" prefix="/myPrefix"> <file alias="ui.qml">../../../data/quick/uiMain.qml</file> <file alias="otherComponent.qml">../../../data/quick/otherComponent.qml</file> // etc...
The main file now loads correctly, but QML files (types) in the same subdir are not recognized anymore.
I tried this:
import "qrc:myPrefix/otherComponent.qml" as OtherComponent
But I get errors such as
OtherComponent cannot be used as a type. Also, this type of import isn't documented anywhere. All the docs say that other QML files in the same subdir should be recognized automatically.
What is the correct way to handle this? Preferably without adding dozens of import statements all over my 20 QML files.
You don't need the import statement at all, the OtherComponent file is already in the same directory (it's name should start with a capital letter, though!).
And if you really want to use the QRC notation, it should look like this:
import "qrc:/myPrefix/otherComponent.qml" as OtherComponent