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. Error creating a QQmlComponent (resource not found)
QtWS25 Last Chance

Error creating a QQmlComponent (resource not found)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlresourceserrorcmake
5 Posts 3 Posters 3.1k 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.
  • J Offline
    J Offline
    jonyAL
    wrote on 13 Apr 2016, 10:52 last edited by A Former User 5 Oct 2016, 12:54
    #1

    Hi everyone.

    I am having several problems porting a quick application from Android to Desktop.
    In this process I must to change from .pro to CMakeLists.txt (I am working on ROS and I need to define a CMakeLists.txt).

    The problem is that I cant find the resources files when I try to compile with cmake. However I have not problems when I use the .pro file.

    My system files:

    |- Project
        |- CMakeLists.txt
        |- src/
            |- main.cpp
            |- ...
        |- resources/
            |- main.qml
            |- qml.qrc
        |- ... 
    

    The CMakeLists.txt contains:

    [...]
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    set(QRC_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources/qml.qrc)
    [...]
    

    In the Andoid version (working properly), i had put in my .pro:

    [...]
    RESOURCES += resources/qml.qrc
    [...]
    

    The .qrc file:

    <RCC>
        <qresource prefix="/">
            <file>main.qml</file>
        </qresource>
    </RCC>
    

    And finally, in my code:

    QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
    

    The execution error is:

    (qrc:/main.qml: File not found) 
    

    How do I to find the resouces files with cmake compilation?

    Thank you so much,
    jonyAL

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Apr 2016, 21:29 last edited by
      #2

      Hi and welcome to devnet,

      Did you already check the cmake manual from Qt's documentation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        treaves
        wrote on 14 Apr 2016, 11:55 last edited by
        #3

        With cmake, there are three things you do (or at lest I do) to get the resources added.

        SET(PROJECT_RESOURCES
            ../resources/resources.qrc
        )
        qt5_add_resources(PROJECT_RESOURCES_CXX ${PROJECT_RESOURCES})
        
        add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE} ${PROJECT_RESOURCES_CXX})
        
        

        So you :

        • create the variable to hold the src file
        • use the qt5_add_resources macro
        • add the files from the qt5_add_resources macro to your executable (or library), as you would other sources.

        Hope this helps.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          treaves
          wrote on 14 Apr 2016, 11:58 last edited by
          #4

          Also, please add the cmake tag to this post; I don't think a responder can.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jonyAL
            wrote on 10 May 2016, 12:43 last edited by
            #5

            I solved this problem.

            I just added this lines in my CMakeLists.txt

            qt5_add_resources(QT_RESOURCES_CPP resources/qml.qrc)
            
            add_executable(my_app
                             src/my_app.cpp src/my_app.h ${QT_RESOURCES_CPP})
            
            target_link_libraries(my_app
                                    lib1
                                    lib2
                                    ...)
            

            The problem was that I was adding my reference to QT_RESOURCES_CPP in the target_link_libraries(...) instead of add_executable(...). For some reason this didn't work properly.

            Thank you,
            Jonatan

            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