Qt not displaying PNG images on Linux
I have a software written using Qt
which is meant to work on both开发者_StackOverflow Windows and Linux.
I use PNG images as icons for my QAction
s, embedded in a resource.
I have the following tree directory:
/
resources/
icons.qrc
image.png
Here is the content of icons.qrc
:
<RCC>
<qresource prefix="/resources" lang="fr">
<file alias="image.png">image.png</file>
</qresource>
</RCC>
I declare my QIcon
like that:
QIcon(":/resources/image.png")
Under Windows, it works well but on Linux (I only tried on Ubuntu 10.4 so far), the images aren't displayed.
Is there anything special I have to do for this to work ? Is this a configuration problem ?
Thank you.
It seems that it's all ok with you code.
Try to add this definition to your pro-file. I'm not really sure, but still we can try:
QTPLUGIN += qpng
and to your mainwindow.cpp
#include <QtPlugin>
Q_IMPORT_PLUGIN(qpng)
Actually, I found out what was wrong.
It had nothing to do with being on Linux or Windows, it was due to the locale.
My linux system is in english while my Windows is in french. Since the resources had the lang="fr"
flag, nothing was shown on non-french OSes...
A stupid mistake !
I found a solution.
In windows ==> copy "imageformats" folder in Qt system folder to your EXE program folder.
In linux ==> install libpng package.
then you will see the PNG image in your program.
In ubuntu, my program didn't display PNG image.
I installed libpng package (libpng16.* : sudo apt-get install libpng16*),
then my program displayed PNG image (toolbar button, splash window, and something).
精彩评论