views:

166

answers:

2

Hi,

I have a software written using Qt which is meant to work on both Windows and Linux.

I use PNG images as icons for my QActions, 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.

+1  A: 

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)
mosg
Thanks for your answer. Once I did that, the linking fails because he doesn't find "libqpng".
ereOn
So you need to rebuild Qt library with libpng support, i think...
mosg
@mosg I tried with `.bmp` and `.jpg` as well, without result. Shouldn't it at least support these two ? I'll try to figure out with which options it was compiled.
ereOn
@ereOn Did you tried to use absolute path to images (with different formats)? I mean with out using resources...
mosg
@mosg Yep. That's the first thing I tried. :/
ereOn
Also try to build your own Qt libs, from the sources... Or you did this to? Have a look also to the examples where using images... I remember one thing: on linux try: *QIcon("/resources/image.png")*, without ":" symbol...
mosg
@mosg I just compiled the last version from the sources but still no images are shown. Could it be a conflict with Qt3 ?!
ereOn
I think Qt3 also supports images... I'll try to compile some Qt examples with images, today, on my OpenSuse 11.3 ... because just for now, I really don't know what is wrong with you code.
mosg
@mosg I finally found out, thank you for your help/your time.
ereOn
+1  A: 

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 !

ereOn