QML component unable to find other QML components
-
Hello,
I'm new to QML and have been working through the guides. Originally I had my qml files in the top project directory and all was good. From C++ I was able to load the main.qml file like so:
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
And in the qmake file:
RESOURCES += qml.qrc
I stumbled upon the 'Best Practices' guide and moved all my QML files to a 'qml' directory. I've updated the paths in the .qrc file and C++ like so:
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
Now when I try to run my project I get the following error:
QML debugging is enabled. Only use this in a safe environment. QQmlApplicationEngine failed to load component qrc:/qml/main.qml:149 Type LockedScreen unavailable
Since the 'LockedScreen' QML component is now in the qml directory it seems other QML components cannot find it.
Here is like 149 from 'main.qml':
initialItem: LockedScreen { }
How can I get this to work? I have 'LockedScreen.qml' as its own file in the qml directory.
Thanks.
-
@mjohn
maybe a stupid question, but did you also add the LockedScreen component also qrc file?
If so please post the qrc contents -
Here is my qrc file. It does include the LockedScreen component.
<RCC> <qresource prefix="/"> <file>qml/main.qml</file> <file>qml/AuthenticationUserPin.qml</file> <file>qml/CommandBar.qml</file> <file>qml/Home.qml</file> <file>qml/LockedScreen.qml</file> <file>qml/NumericKeypad.qml</file> </qresource> </RCC>
And project structure:
. ├── fonts │ ├── ... ├── images │ ├── .... ├── main.cpp ├── NGS2_FG.pro ├── NGS2_FG.pro.user ├── NGS2-UI.pro ├── NGS2-UI.pro.user ├── qml │ ├── AuthenticationUserPin.qml │ ├── CommandBar.qml │ ├── Home.qml │ ├── LockedScreen.qml │ ├── NumericKeypad.qml │ └── main.qml ├── qml.qrc ├── resources.qrc ├── sessiondata.cpp └── sessiondata.h