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 file not found in resource system (qrc) despite correct qml.qrc configuration
Forum Updated to NodeBB v4.3 + New Features

QML file not found in resource system (qrc) despite correct qml.qrc configuration

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 103 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.
  • A Offline
    A Offline
    Actarus
    wrote last edited by
    #1

    Hello,
    I'm facing a persistent issue with a Qt Quick application using Qt 6.9.1 (also reproduced in Qt 5.15.8):

    Despite having correctly defined my qml.qrc and file structure, QQmlApplicationEngine fails to load my QML file, reporting:

    QQmlApplicationEngine failed to load component  
    qrc:/ui/qml/Screen.qml: No such file or directory  
    QML file exists? false  
    Files in qrc:/ui/qml: QList("ui")
    

    My setup:
    Qt version: 6.9.1 (MinGW 64-bit) and 5.15.8 (tested on both)

    OS: Windows 10

    Using CMake

    Project structure:

    /project-root
    ├── src/
    │   └── main.cpp
    ├── ui/qml/
    │   └── Screen.qml
    ├── qml.qrc
    ├── CMakeLists.txt
    
    

    qml.qrc content:

    <RCC>
        <qresource prefix="/ui/qml">
            <file>ui/qml/Screen.qml</file>
        </qresource>
    </RCC>
    
    

    CMakeLists.txt (relevant part):

    qt_add_executable(MotorsportApp
        src/main.cpp
        qml.qrc
    )
    
    target_link_libraries(MotorsportApp PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick)
    
    

    main.cpp (minimal test):

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QDebug>
    #include <QDir>
    #include <QFile>
    
    int main(int argc, char *argv[]) {
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
    
        qDebug() << "Files in qrc:/ui/qml:" << QDir(":/ui/qml").entryList();
        qDebug() << "QML file exists?" << QFile::exists(":/ui/qml/Screen.qml");
    
        engine.load(QUrl(QStringLiteral("qrc:/ui/qml/Screen.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    
    

    What I've tried:
    Clean build, delete build folder

    Reimport project in Qt Creator

    Encoding of qml.qrc set to UTF-8 without BOM

    Verified that Screen.qml exists at the expected path

    Resource path is referenced exactly as in .qrc

    Verified qml.qrc is included in CMake

    Also tried qt_add_resources() with PREFIX and BASE

    Still, at runtime, the resource system only shows "ui" in qrc:/ui/qml/, and not the actual file.

    Any idea what could be causing this? Is this a bug in qmlimportscanner or rcc on Windows?

    Thanks in advance!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Actarus
      wrote last edited by
      #2

      Here the project tree:

      Tree.jpg

      JonBJ 1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #3

        So your path is ui/qml/ui /qml which is not what you pass to engine.load(). Fix your CMakeLists.txt or your call to load()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        2
        • A Actarus

          Here the project tree:

          Tree.jpg

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by
          #4

          @Actarus
          It sounds like you got messed up at some point and created unintended repeats of folders?

              <qresource prefix="/ui/qml">
                  <file>ui/qml/Screen.qml</file>
              </qresource>
          

          Feels like one of prefix= or <file> path is duplicate. This is going to deliver /ui/qml/ui/qml/Screen.qml.

          A 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            So your path is ui/qml/ui /qml which is not what you pass to engine.load(). Fix your CMakeLists.txt or your call to load()

            A Offline
            A Offline
            Actarus
            wrote last edited by
            #5

            @Christian-Ehrlicher Thanks Christian, solved using qt_add_resources() instead.

            1 Reply Last reply
            0
            • JonBJ JonB

              @Actarus
              It sounds like you got messed up at some point and created unintended repeats of folders?

                  <qresource prefix="/ui/qml">
                      <file>ui/qml/Screen.qml</file>
                  </qresource>
              

              Feels like one of prefix= or <file> path is duplicate. This is going to deliver /ui/qml/ui/qml/Screen.qml.

              A Offline
              A Offline
              Actarus
              wrote last edited by
              #6

              @JonB Thanks Jon, that was the reason but even without duplication it didn't work, so I solved it using qt_add_resources() instead.

              JKSHJ 1 Reply Last reply
              0
              • A Actarus has marked this topic as solved
              • A Actarus

                @JonB Thanks Jon, that was the reason but even without duplication it didn't work, so I solved it using qt_add_resources() instead.

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote last edited by
                #7

                @Actarus said in QML file not found in resource system (qrc) despite correct qml.qrc configuration:

                I solved it using qt_add_resources() instead

                I'm glad to hear that you were able to resolve your issue.

                As the next step, I recommend taking the time to port from qt_add_resources() to qt_add_qml_module(): https://doc.qt.io/qt-6/qt6-port-to-qt-add-qml-module.html

                This provides your projects with benefits such as optimization by the Qt Quick Compiler (https://www.qt.io/blog/the-numbers-performance-benefits-of-the-new-qt-quick-compiler) and improved code analysis by your IDE.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                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