CMAKE - Adding the QRC files & Accessing the qml inside
-
Hi
How to add QRC files to CMAKE & access qml files inside the Qrc files.
Starting with Qt now.
- Qt 6.4 & Mac
- Create the CMake Project
- 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.
-
Hi
How to add QRC files to CMAKE & access qml files inside the Qrc files.
Starting with Qt now.
- Qt 6.4 & Mac
- Create the CMake Project
- 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.
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 problemsset(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>