QML SystemTrayIcon icon from QML module not showing
-
Hello.
I am facing a bug that I cannot understand on macOS using Qt 6.7.2 when trying to display an icon for the
SystemTrayIcon
QML widget.This is the
Main.qml
loaded withengine.loadFromModule("qmlModule", "Main");
:SystemTrayIcon { property Window window: Window { visible: true width: 400 height: 400 Image { anchors.fill: parent source: "assets/icons/bad.png" } } icon.source: "assets/icons/bad.png" visible: true }
For some reasons, the
icon.source
does not work, nothing is visible in the system tray while there is no problem in theImage
with the same asset.Assets are added to the QML module with the
RESSOURCES
option ofqt_add_qml_module
CMake function.Maybe it is also linked but the
showMessage
from theSystemTrayIcon
also does not work.I have tried the Qt sample project
Systray
and it works well (icon andshowMessage
) but it is using QWidget.Any idea on what is going on ?
Thanks. -
Then check with
qrc:/myproject/qml/assets/icons/bad.png
.icon.source
is aurl
so it requires a scheme hence theqrc:/
. It should be the same for Image though. -
Hi,
I haven't used that yet but intuitively since you mention resources, I would think that you need to prefix the path with
qrc:/
.Both path should then be
qrc:/assets/icons/bad.png
. -
That is what I thought at first.
But using qt_add_qml_module and especially the RESOURCE argument it will create a
qrc
file with aliases.For instance it creates this
qrc
file:<RCC> <qresource prefix="/myproject/"> <file alias="qml/assets/icons/bad.png">`project_path`/qml/assets/icons/bad.png</file> </qresource> </RCC>
If I follow how resource file works and especially prefixes and alliases, I should be able to reference the file with
:/<prefix>/<file alias>
.Therefore, in my case, I should be able to use
:/myproject/qml/assets/icons/bad.png
but it does not work. It only work withassets/icons/bad.png
and only for theImage
, not theSystemTrayIcon
. As I am writing this, I think I understand why it works that way (at least for theImage
) as it is a relative path pointing to the "local resource". -
Then check with
qrc:/myproject/qml/assets/icons/bad.png
.icon.source
is aurl
so it requires a scheme hence theqrc:/
. It should be the same for Image though. -