admin管理员组文章数量:1122846
I am trying to add icons to my QML QtQuick app, the build process is fine, but when I launch the executable I get this error message:
> ./dataio
QML debugging is enabled. Only use this in a safe environment.
QQmlApplicationEngine failed to load component
qrc:/qt/qml/DataIO/Main.qml:40:5: Cannot assign to non-existent property "icon"
The Main.qml
line 40 is:
icon: "qrc:/qt/qml/DataIO/images/DataIO.png"
The DataIO.png
file is located here:
~/source/ui_qml/DataIO/images/DataIO.png
~/DataIO_build/Desktop-Debug/DataIO/images/DataIO.png
I tried to specify the icon path in different ways, all with the same error:
icon: "./images/DataIO.png"
icon: "DataIO/images/DataIO.png"
icon: "DataIO.png"
icon: "qrc:/images/DataIO.png"
icon: "qrc:/DataIO/images/DataIO.png"
icon: "qrc:DataIO.png"
icon.source: "images/DataIO.png"
...
If I define a widget, specifying an icon as follows seems to be fine, I get no warnings/errors, but the icon effectively displayed is a default one, not the one specified:
Action {
text: qsTr("&Connect...")
icon.source: "images/DataIO.png"
onTriggered: QmlLink.connect()
}
I have a manually written resource.qrc
file in my source directory:
<RCC>
<qresource prefix="/">
<file>images/DataIO.png</file>
</qresource>
</RCC>
This is added to CMakeLists.txt
in the qt_add_executable
call:
set(CMAKE_AUTORCC ON)
qt_add_executable(dataio
main.cpp DataIO.hpp DataIO.cpp
resource.qrc
)
qt_add_qml_module(dataio
URI DataIO
VERSION 0.1
QML_FILES
Main.qml
RESOURCES
images/DataIO.png
)
In the build directory three qrc
files are generated, one of which is a modified version of the manually written one:
<RCC>
<qresource prefix="/qt/qml/DataIO/">
<file alias="Main.qml">/home/pietrom/DataIO/Main.qml</file>
<file alias="images/DataIO.png">/home/pietrom/DataIO/images/DataIO.png</file>
</qresource>
</RCC>
Thank you for your help.
Platform:
- Ubuntu 24.10
- Qt 6.6
本文标签: qtIcons not found when launching a QML appprogram abortsStack Overflow
版权声明:本文标题:qt - Icons not found when launching a QML app, program aborts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309538a1934056.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论