QML Image: Cannot open - CMake qrc
-
@JoeCFD Thank you so much for responding. The build directory does not have the qrc_resources.cpp file that you meant. These are all the cpp files generated after building the project.
Is there something else that I could be doing wrong? The project has successfully included the qrc file to be seen and interacted with on Qt Creator. But after build and run, it is disregarded.
-
Was facing the same problem too, i found out that i need to add
set(CMAKE_AUTORCC ON)
to the cmake file and it's working now.
Try adding it this may be the answer to your problemEdit : make sure to add this line before the
qt_add_executable(appqml_testing main.cpp qml/resources/resource.qrc )
line
-
-
@JohnKS said in QML Image: Cannot open - CMake qrc:
set(CMAKE_AUTORCC ON)
I found that if I add the line "qml/resources/resource.qrc" where you suggest I get a compile error.
I simply added resource.qrc to the modules section like this:
qt_add_qml_module(appBasicElementsDemoImage
URI BasicElementsDemoImage
VERSION 1.0
QML_FILES Main.qml resource.qrcAdding the set(CMAKE_AUTORCC ON) worked just fine.
-
@Colins2 It is maybe also worth noting that in the CMakelists template for a Qt Widgets application, i.e. a C++ app, the set(CMAKE_AUTORCC ON) statement is present by default.
I have now added this to my QtQuick template to avoid future problems. -
This post seem to work for me:
https://doc.qt.io/qt-6/cmake-build-qml-application.html
I didn't need to add
set(CMAKE_AUTORCC ON)
Relevant part of CMakeLists.txt:
qt_add_qml_module(appqmlDemo URI qmlDemo VERSION 1.0 QML_FILES Main.qml RESOURCES images/menu_24px.png )
My project structure:
├── CMakeLists.txt ├── CMakeLists.txt.user ├── images │ └── menu_24px.png ├── main.cpp ├── Main.qml
I used the image in the qml file as:
ToolButton { id: menuButton anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter icon.source: "images/menu_24px.png" onClicked: drawer.open() }
-
@JohnKS Wow, I just spent like an hour trying to figure this out and copying detailed tutorials verbatim to try and get it working and it's this non-default flag that apparently doesn't always need to be set seeing as it doesn't appear anywhere in Qt's examples. It would be really helpful if this was mentioned more prominently somewhere.