Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "No such file or directory" error qrc
QtWS25 Last Chance

"No such file or directory" error qrc

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 294 Views
  • 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
    AstroFinch
    wrote on 5 Apr 2025, 09:28 last edited by
    #1

    Hey all,
    I've just been playing around with QT for the first time, but I've hit a roadblock with the RCC system.
    To my knowledge, the system compiles resources alongside the executable and stores them as one file, which sounds great, but I continue to get the error:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml: No such file or directory
    

    Whenever I attempt to run my project. I have four files in my root directory, CMakeLists.txt, main.cpp, resources.qrc and a folder named 'ui' that contains main.qml.
    From what I can see from the online resources, everything should be working, and my code complies with what is said in the documentation. I am developing via jetbrains CLion on fedora linux with QT 6.9, but I doubt the issue is caused by problems with CLion as everything else has functioned flawlessly.

    What the program should do is launch a simple window with the text "Welcome", by loading the main.qml file as a little test platform.

    Any help would be greatly appreciated.

    CMakeLists.txt:

    cmake_minimum_required(VERSION 3.30)
    project(test)
    
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    
    set(CMAKE_PREFIX_PATH "/home/user/Qt/6.9.0/gcc_64/")
    
    find_package(Qt6 COMPONENTS
      Core
      Qml
      Gui
      Widgets
      Quick
      REQUIRED)
    
    #set(CMAKE_AUTORCC_SEARCH_PATHS ${CMAKE_SOURCE_DIR})
    
    add_executable(test main.cpp)
    qt_add_resources(test resources.qrc)
    
    target_link_libraries(test
      Qt::Core
      Qt::Gui
      Qt::Widgets
      Qt::Quick
      Qt::Qml
    )
    
    

    main.cpp:

    #include <iostream>
    #include <QApplication>
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    
    
    int main(int argc, char *argv[]) {
        {
            QGuiApplication app(argc, argv);
    
            QQmlApplicationEngine engine;
    
            /*QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
                             &app, []() { QCoreApplication::exit(-1); },
                             Qt::QueuedConnection);*/
    
    
            engine.load("qrc://ui/main.qml");
    
            if (engine.rootObjects().isEmpty())
                return -1;
    
            return app.exec();
        }
    }
    

    resources.qrc:

    #include <iostream>
    #include <QApplication>
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    
    
    int main(int argc, char *argv[]) {
        {
            QGuiApplication app(argc, argv);
    
            QQmlApplicationEngine engine;
    
            /*QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
                             &app, []() { QCoreApplication::exit(-1); },
                             Qt::QueuedConnection);*/
    
    
            engine.load("qrc://ui/main.qml");
    
            if (engine.rootObjects().isEmpty())
                return -1;
    
            return app.exec();
        }
    }
    

    main.qml:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        id: mainWindow
        width: 640
        height: 480
        visible: true
        title: qsTr("test")
    
        Text {
            anchors.centerIn: parent
            text: qsTr("Welcome.")
        }
    }```
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 5 Apr 2025, 09:31 last edited by
      #2

      You qresources.qrc is wrongly pasted I would guess.

      engine.load("qrc://ui/main.qml");

      I would be surprised if Qt would complain about qrc:/main.qml then.

      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 5 Apr 2025, 12:18
      1
      • C Christian Ehrlicher
        5 Apr 2025, 09:31

        You qresources.qrc is wrongly pasted I would guess.

        engine.load("qrc://ui/main.qml");

        I would be surprised if Qt would complain about qrc:/main.qml then.

        A Offline
        A Offline
        AstroFinch
        wrote on 5 Apr 2025, 12:18 last edited by
        #3

        @Christian-Ehrlicher
        Unfortunately it seems like everything it correctly pasted. All URIs for the main.qml file are identical, and modifying the project so that main.qml is in the root directory and all URIs point to that new location still returns the same error.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 5 Apr 2025, 12:53 last edited by Christian Ehrlicher 5 days ago
          #4

          What you posted for resources.qrc if no xml but c++ code...

          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 5 Apr 2025, 13:18
          0
          • C Christian Ehrlicher
            5 Apr 2025, 12:53

            What you posted for resources.qrc if no xml but c++ code...

            A Offline
            A Offline
            AstroFinch
            wrote on 5 Apr 2025, 13:18 last edited by AstroFinch 5 days ago
            #5

            @Christian-Ehrlicher Oh yes, sorry, I must have accidentally pasted the CPP twice instead of copying the .qrc.

            EDIT: I can't seem to edit the original post anymore, so I've appended the .qrc here:

            <!DOCTYPE RCC>
            <RCC>
                <qresource>
                    <file>main.qml</file>
                </qresource>
            </RCC>
            
            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 5 Apr 2025, 18:16 last edited by Christian Ehrlicher 5 days ago
              #6

              It must be QUrl("qrc:/main.qml") or ":/main.qml" according to https://doc.qt.io/qt-6/resources.html#qt-resource-collection-file-qrc and https://doc.qt.io/qt-6/resources.html#runtime-api

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AstroFinch
                wrote on 7 Apr 2025, 12:03 last edited by
                #7

                SOLVED:

                I eventually discovered this little section in the QT docs: https://doc.qt.io/qt-6/resources.html#cmake

                Turns out that resources.qrc that linked to main.qml needed to be listed as an executable in CMakeLists.txt, in the line:

                add_executable(test main.cpp resources.qrc)
                

                I would have assumed that a qrc file would logically be listed as a resources using:

                qt_add_resources(test resources.qrc)
                

                but apparently not. main.qml was nowhere to be seen in the QRC file system, but after adding the .qrc file as an executable it has appeared and it usable.

                jsulmJ 1 Reply Last reply 7 Apr 2025, 12:35
                0
                • A AstroFinch has marked this topic as solved on 7 Apr 2025, 12:04
                • A AstroFinch
                  7 Apr 2025, 12:03

                  SOLVED:

                  I eventually discovered this little section in the QT docs: https://doc.qt.io/qt-6/resources.html#cmake

                  Turns out that resources.qrc that linked to main.qml needed to be listed as an executable in CMakeLists.txt, in the line:

                  add_executable(test main.cpp resources.qrc)
                  

                  I would have assumed that a qrc file would logically be listed as a resources using:

                  qt_add_resources(test resources.qrc)
                  

                  but apparently not. main.qml was nowhere to be seen in the QRC file system, but after adding the .qrc file as an executable it has appeared and it usable.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 7 Apr 2025, 12:35 last edited by
                  #8

                  @AstroFinch said in "No such file or directory" error qrc:

                  needed to be listed as an executable

                  It is not listed as an executable (your executable is named "test"). It is listed as a source item to build your executable (just like main.cpp).

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  1/8

                  5 Apr 2025, 09:28

                  • Login

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