Important: Please read the Qt Code of Conduct -

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;

    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;

    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.


  • Moderators

    maybe a stupid question, but did you also add the LockedScreen component also qrc file?
    If so please post the qrc contents

  • @raven-worx

    Here is my qrc file. It does include the LockedScreen component.

        <qresource prefix="/">

    And project structure:

    ├── fonts
    │   ├── ...
    ├── images
    │   ├── ....
    ├── main.cpp
    ├── qml
    │   ├── AuthenticationUserPin.qml
    │   ├── CommandBar.qml
    │   ├── Home.qml
    │   ├── LockedScreen.qml
    │   ├── NumericKeypad.qml
    │   └── main.qml
    ├── qml.qrc
    ├── resources.qrc
    ├── sessiondata.cpp
    └── sessiondata.h

  • Moderators

    did you make a complete clean rebuild yet?

    deleting buildfolder, running qmake, than build&run

    after messing with your qrc file you should do that, so no other remnands from the last build remain

  • @J-Hilk

    I've ran a 'clean all' and tried again. It still builds fine, the error occurs when I try to run.

Log in to reply