Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML component unable to find other QML components
Qt 6.11 is out! See what's new in the release blog

QML component unable to find other QML components

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjohn
    wrote on last edited by
    #1

    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.

    raven-worxR 1 Reply Last reply
    0
    • M mjohn

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mjohn
        wrote on last edited by
        #3

        @raven-worx

        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
        
        J.HilkJ 1 Reply Last reply
        0
        • M mjohn

          @raven-worx

          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
          
          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @mjohn
          question,
          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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mjohn
            wrote on last edited by
            #5

            @J-Hilk

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved