Reputation: 3
I'm dealing with this simple yet frustrating problem for a long time in Qt6.
I create a new Qt Quick project and set my Android Qt Clang x86_64 kit (cmake). The issue starts when I want to add an image in my application. I add the image into the projects folder and use the code
Image{ source = "profilna.png" }
, but when I built it, I got a warning saying : "libappuntitled3_x86_64.so: qrc:/untitled3/Main.qml:10:5: QML Image: Cannot open: qrc:/untitled3/profilna.png" in the Application Output. I'm a complete beginner in Qt Quick and don't understand why it works in Desktop MinGW kit and not on Android. After that I added resource.qrc (prefix name "/img") and added the image (that is in a folder "img") there, but it still doesn't work. I have also addedset(CMAKE_AUTORCC ON)
, didn't work.
main.qml
import QtQuick
import QtQuick.Window
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Image{
x: 62
y: 39
width: 153
height: 345
source:"qrc:/img/img/profilna.png"
}
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(untitled3 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
qt_standard_project_setup()
qt_add_executable(appuntitled3
main.cpp
)
qt_add_qml_module(appuntitled3
URI untitled3
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(appuntitled3 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(appuntitled3
PRIVATE Qt6::Quick
)
install(TARGETS appuntitled3
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
resource.qrc
<RCC>
<qresource prefix="/img">
<file>img/profilna.png</file>
</qresource>
</RCC>
Upvotes: 0
Views: 709
Reputation: 8277
I don't see anywhere in your cmake file where you include your resource.qrc file. But you shouldn't even need to manually create that file anymore in Qt6. In your cmake file, add your images this way:
qt_add_resources(appuntitled3 "assets"
PREFIX "/img"
FILES "img/profilna.png"
)
Your qml should then be able to access "qrc:/img/img/profilna.png".
Upvotes: 1