For the last couple of hours I'm trying to solve problem with displaying icon in QAction.
The problem is that icon isn't shown, only text decryption is placed on its position 'Roads'.
I've tried to debug it and all the time QPixmap is NULL, looks like it can't find file.
Here's how my code looks like:
QPixmap icon(":/road.png");
QAction *A1 = new QAction(icon,"Road...", 0);
A1->setIconVisibleInMenu(true);
A1->setVisible(true);
connect(A1, SIGNAL(triggered()), SLOT(triggeredA1()));
I've read this article. According to it I've changed my pro file by adding line:
RESOURCES = ./res/icons.qrc
In src directory I've created subdir 'res' and placed there my icons:
-src
--res
road.png
load.gif
done.gif
Here's how my icons.qrc file looks like:
<RCC>
<qresource prefix="/">
<file>road.png</file>
<file>done.gif</file>
<file>load.gif</file>
</qresource>
</RCC>
Even after all this manipulations QPixmap still NULL. What am I doing wrong?
Solution:
I'm using OS X and built Qt4 with MacPorts. For some reason libpng isn't included in build provided by MacPorts. So, the solution is to build libpng via MacPorts manually:
sudo port install libpng
and include this lib to your project by adding following line in .pro file
LIBS += -lpng
After this steps you can use .png files in your project as it was written above.