I have a statically compiled Qt application. It has its resource file pointing to a directory under the directory where the working directory is located, with the main.cpp, the .pro file etc. Something like that:
Proyecto
|-main.cpp
|-mainwindows.h
|-mainwindows.cpp
|-..........
|-iconos.qrc
|-/Iconos|-icono1.png
|-/Iconos|-icono2.png
|-/Iconos|............
etc
The content of the icons.qrc file:
<RCC>
<qresource prefix="/">
<file>Iconos/trucking.png</file>
<file>Iconos/engineer.png</file>
<file>Iconos/brick.png</file>
<file>Iconos/delete.png</file>
<file>Iconos/file.png</file>
<file>Iconos/folder.png</file>
<file>Iconos/sinclasificar.png</file>
</qresource>
</RCC>
In the *.pro file I have included the file:
RESOURCES += \
iconos.qrc
And the way to call them (this is one of them):
QIcon icono ("../Proyecto/Iconos/brick.png");
QPushButton* buton = new QPushButton(icono,"");
I also have to say that the taskbar icons do not have that problem. They are icons that appear in tables, both within cells and in a layout within mainwindows
The thing is that when compiling from Qt Creator, I have no problems, but when running the application from outside, it no longer saves the path of the icons. Seeing this:
https://doc.qt.io/qt-5/resources.html I interpret that the macro should be put at the beginning Q_INIT_RESORUCE(nombre_del_archivo_qrc_sin_extension)
but I don't get anything. I can always copy the directory with the icons under the executable, but I understand that it is not the solution.
So the question is... how to incorporate the icons to the executable so that they are always available?
This is bad:
Because you are not using the icons from the resource file but loading them directly from the file system.
Since the resources you are loading them like this:
The resource load would be:
The colon at the beginning indicates that the load is from a resource. The route is the one indicated in the field
<file>