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