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. CMAKE - Adding the QRC files & Accessing the qml inside

CMAKE - Adding the QRC files & Accessing the qml inside

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    guru_desh
    wrote on last edited by guru_desh
    #1

    Hi

    How to add QRC files to CMAKE & access qml files inside the Qrc files.

    Starting with Qt now.

    1. Qt 6.4 & Mac
    2. Create the CMake Project
    3. I'm able to compile & run the program.

    I added the new QRC file called TestMe.qrc.
    Added on TestMe.qrc file to CMAKE project.

    Add the cmake configuration like the following.

    set(CMAKE_AUTORCC ON)
    qt_add_resources(RESOURCE_FILES TestMe.qrc)
    
    qt_add_executable(appTest_1
        main.cpp
        ${RESOURCE_FILES}
    )
    

    Inside the main.qml file

    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        MyButton {
            text : "Gururaja"
        }
        TestQRC{
            text : "Testing the QRC NOW..."
        }
    }
    

    When I run the program It says TestQRC file is not found.

    Please note that without qrc files I'm able to add the QML file & image file directly like the following.

    qt_add_qml_module(appTest_1
        URI Test_1
        VERSION 1.0
        QML_FILES Main.qml
        QML_FILES MyButton.qml
        RESOURCES NeckPillow_3.jpg
    )
    

    This works.

    However adding the QML files through new QRC Files & adding the qrc file to the CMake project is not working.

    Any input ? Thank you.

    SebastianoS 1 Reply Last reply
    0
    • G guru_desh

      Hi

      How to add QRC files to CMAKE & access qml files inside the Qrc files.

      Starting with Qt now.

      1. Qt 6.4 & Mac
      2. Create the CMake Project
      3. I'm able to compile & run the program.

      I added the new QRC file called TestMe.qrc.
      Added on TestMe.qrc file to CMAKE project.

      Add the cmake configuration like the following.

      set(CMAKE_AUTORCC ON)
      qt_add_resources(RESOURCE_FILES TestMe.qrc)
      
      qt_add_executable(appTest_1
          main.cpp
          ${RESOURCE_FILES}
      )
      

      Inside the main.qml file

      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          MyButton {
              text : "Gururaja"
          }
          TestQRC{
              text : "Testing the QRC NOW..."
          }
      }
      

      When I run the program It says TestQRC file is not found.

      Please note that without qrc files I'm able to add the QML file & image file directly like the following.

      qt_add_qml_module(appTest_1
          URI Test_1
          VERSION 1.0
          QML_FILES Main.qml
          QML_FILES MyButton.qml
          RESOURCES NeckPillow_3.jpg
      )
      

      This works.

      However adding the QML files through new QRC Files & adding the qrc file to the CMake project is not working.

      Any input ? Thank you.

      SebastianoS Offline
      SebastianoS Offline
      Sebastiano
      wrote on last edited by
      #2

      @guru_desh

      Hello,

      the main.qml is in the .qrc ?
      if not where do you launch the main.qml file from?

      I tried to reproduce your example like this:
      I can launch the whole thing without any problems

      set(CMAKE_AUTORCC ON)
      
      qt_add_resources(RESOURCE_FILES application.qrc)
      
      qt_add_executable(appuntitled
          main.cpp
          ${RESOURCE_FILES}
      )
      
      

      in the file main.qml

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Test {
              id: test
      
              height: parent.height/2
              width: parent.width/2
          }
      }
      

      In the file main.cpp

      QQmlApplicationEngine engine;
          const QUrl url(u"qrc:/Main.qml"_qs);
          QObject::connect(
              &engine,
              &QQmlApplicationEngine::objectCreationFailed,
              &app,
              []() { QCoreApplication::exit(-1); },
              Qt::QueuedConnection);
          engine.load(url);
      

      and in the file .qrc

      <RCC>
          <qresource prefix="/">
              <file>Test.qml</file>
              <file>Main.qml</file>
          </qresource>
      </RCC>
      
      
      1 Reply Last reply
      1

      • Login

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