Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, May 2007
PNG icons don't display under windows QT


Message 1 in thread

Dear All,
I have piece of sw which I've tried to compile under windows. It works,
however all icons stored in PNG format do not
display at all. The QT is version 4.2.3, icons are stored in icon resource
file and they are assigned to tool buttons
like this:

d_addLayer->setIcon(QIcon(QString::fromUtf8(":/menu_images/plus.png")));

this works great under linux, doesn't work under windows. The QT is compiled
with -qt-libpng


Does anyone have clue what's up?

thanks
d.

Message 2 in thread

Hi,
 
It looks that the directory starting with : is not valid on Windows. I
display plenty of pngs and have not experienced a problem with that yet.
 
Cheers,
Sandor

-----Original Message-----
From: qt-interest-request@xxxxxxxxxxxxx
[mailto:qt-interest-request@xxxxxxxxxxxxx]On Behalf Of dejfson
Sent: 25/05/2007 12:32
To: qt-interest@xxxxxxxxxxxxx
Subject: PNG icons don't display under windows QT


Dear All,
I have piece of sw which I've tried to compile under windows. It works,
however all icons stored in PNG format do not 
display at all. The QT is version 4.2.3, icons are stored in icon resource
file and they are assigned to tool buttons 
like this:

d_addLayer->setIcon(QIcon(QString::fromUtf8(":/menu_images/plus.png")));

this works great under linux, doesn't work under windows. The QT is compiled
with -qt-libpng


Does anyone have clue what's up?

thanks
d.



Message 3 in thread

> It looks that the directory starting with : is not valid on Windows.
> I display plenty of pngs and have not experienced a problem with that 
yet.

No - a directory starting with ":" in Qt means "compiled in resource". 
Take a look at the docs for "The Qt Resource System". But this is 
DEFINITELY valid on windows as well as on linux etc.

You probably have some other problem. Did you use absolute pathes in your 
resource file or something like that?

Regards,
Malte

--
 [ signature omitted ] 

Message 4 in thread

> You probably have some other problem. Did you use absolute pathes in your 
> resource file or something like that?

Or is the resource file included in the Windows project at all? Did it 
compile (check for an object file with the name of the resource file)? 
Any warnings on compilation?

Martin

-- 
 [ signature omitted ] 

Message 5 in thread

Martin Gebert schrieb:
>> You probably have some other problem. Did you use absolute pathes in 
>> your resource file or something like that?
> 
> Or is the resource file included in the Windows project at all? Did it 
> compile (check for an object file with the name of the resource file)? 
> Any warnings on compilation?

And more: does this problem occur also on your development box (where Qt 
is installed), or only on the target machine? In the later case (or 
rather: always): don't forget to install also the necessary Qt plugins 
in your application directory (and/or set the Qt plugin path accordingly 
in your application code).

But at second thought: I just checked my %QTDIR%\plugins\imageformats 
from my (binary distribution) Qt 4.2.2, there is no PNG plugin, only for 
JPEG and MNG etc. Seems like the standard Qt (binary) distribution 
compiles PNG support into the Qt library itself...

Nevertheless, a good thing to remember to copy the necessary Qt plugins 
as well when deploying the application ;)

Cheers, Oliver

--
 [ signature omitted ] 

Message 6 in thread

dejfson schrieb:
> Hi All,
> thanks for responses. The thing is that the path to image is correct and 
> even if I use direct path instead of resource file,
> the image is not displayed. If I use XPM image instead (by using either 
> resource file or direct path), everything works ok.
> 


Can you display PNG images in the Qt example programs? There is an image 
viewer example.

And what happens if you do something like:

   QImage test;

   bool ok = test.load ("c:\valid\path\to\test.png");

What's the value of 'ok'? Does loading the test.png fail as well?

And just to be sure: did you try other PNG images? Does the PNG load in 
other applications all right (e.g. Windows image viewer)?

Cheers, Oliver

--
 [ signature omitted ] 

Message 7 in thread

to make sure the image is loaded into the resource system, I will quite often create an image and verify its not null.

Ie QImage img(":/foo.png")
QASSERT( !img.isNull() )


--Scott
-----Original Message-----
From: dejfson <dejfson@xxxxxxxxx>
Date: Friday, May 25, 2007 2:38 am
Subject: PNG icons don't display under windows QT
To: qt-interest@xxxxxxxxxxxxx

Dear All,
>I have piece of sw which I've tried to compile under windows. It works, however all icons stored in PNG format do not 
>display at all. The QT is version 4.2.3, icons are stored in icon resource file and they are assigned to tool buttons
>
>like this:
>
>d_addLayer->setIcon(QIcon(QString::fromUtf8(':/menu_images/plus.png')));
>
>this works great under linux, doesn't work under windows. The QT is compiled with -qt-libpng
>
>
> Does anyone have clue what's up?
>
>thanks
>d.
> 

--
 [ signature omitted ] 

Message 8 in thread

PROBLEM FOUND - POSSIBLE BUG?

i have used one of the mentioned lines to find out why the PNG doesn't load.
In fact
following code was debugged:

    QPixmap testpix;
    bool fook = testpix.load (QString::fromUtf8(":/menu_images/plus.png"));
    Q_ASSERT_X(fook, "W_layerSettings::W_layerSettings" , "icons failed to
load from resource file!");

by digging into sources this is the point where it fails:

bool QPngHandler::canRead(QIODevice *device)
{
    if (!device) {
        qWarning("QPngHandler::canRead() called with no device");
        return false;
    }

    return device->peek(8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
}

and the reason is following: while they look for combination  89 50 4e 47 0d
0a 1a 0a

my PNG contains however different initial sequence:           89 50 4e 47 0d
(0d 0a) 1a (0d 0a)

looking at the two string it seems that the for each 0a my png contains 0d0a
(it was created under linux).

of course when this identification fails, then canRead returns FALSE and the
image file is not loaded..


Is this an error in my design or it is a bug???




25 May 2007 08:33:00 -0700, Scott Aron Bloom <scott@xxxxxxxxxxxx>:
>
> to make sure the image is loaded into the resource system, I will quite
> often create an image and verify its not null.
>
> Ie QImage img(":/foo.png")
> QASSERT( !img.isNull() )
>
>
> --Scott
> -----Original Message-----
> From: dejfson <dejfson@xxxxxxxxx>
> Date: Friday, May 25, 2007 2:38 am
> Subject: PNG icons don't display under windows QT
> To: qt-interest@xxxxxxxxxxxxx
>
> Dear All,
> >I have piece of sw which I've tried to compile under windows. It works,
> however all icons stored in PNG format do not
> >display at all. The QT is version 4.2.3, icons are stored in icon
> resource file and they are assigned to tool buttons
> >
> >like this:
> >
> >d_addLayer->setIcon(QIcon(QString::fromUtf8(':/menu_images/plus.png')));
> >
> >this works great under linux, doesn't work under windows. The QT is
> compiled with -qt-libpng
> >
> >
> > Does anyone have clue what's up?
> >
> >thanks
> >d.
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

Message 9 in thread

Neither, it is an error in transferring the binary (.png)  file from Linux
to Windows. You transferred it as text.

Keith
**Please do not reply to me, reply to the list.**


On 05-25-2007 4:27 PM, "dejfson" wrote:

> PROBLEM FOUND - POSSIBLE BUG?
> 
> i have used one of the mentioned lines to find out why the PNG doesn't load.
> In fact
> following code was debugged:
> 
>     QPixmap testpix;
>     bool fook = testpix.load (QString::fromUtf8(":/menu_images/plus.png"));
>     Q_ASSERT_X(fook, "W_layerSettings::W_layerSettings" , "icons failed to
> load from resource file!");
> 
> by digging into sources this is the point where it fails:
> 
> bool QPngHandler::canRead(QIODevice *device)
> {
>     if (!device) {
>         qWarning("QPngHandler::canRead() called with no device");
>         return false;
>     }
> 
>     return device->peek(8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
> }
> 
> and the reason is following: while they look for combination  89 50 4e 47 0d
> 0a 1a 0a
> 
> my PNG contains however different initial sequence:           89 50 4e 47 0d
> (0d 0a) 1a (0d 0a)
> 
> looking at the two string it seems that the for each 0a my png contains 0d0a
> (it was created under linux).
> 
> of course when this identification fails, then canRead returns FALSE and the
> image file is not loaded..
> 
> 
> Is this an error in my design or it is a bug???
> 
> 
> 
> 
> 25 May 2007 08:33:00 -0700, Scott Aron Bloom <scott@xxxxxxxxxxxx>:
>> to make sure the image is loaded into the resource system, I will quite often
>> create an image and verify its not null.
>> 
>> Ie QImage img(":/foo.png")
>> QASSERT( !img.isNull() )
>> 
>> 
>> --Scott
>> -----Original Message-----
>> From: dejfson <dejfson@xxxxxxxxx>
>> Date: Friday, May 25, 2007 2:38 am
>> Subject: PNG icons don't display under windows QT
>> To: qt-interest@xxxxxxxxxxxxx
>> 
>> Dear All,
>>> >I have piece of sw which I've tried to compile under windows. It works,
>>> however all icons stored in PNG format do not
>>> >display at all. The QT is version 4.2.3 , icons are stored in icon resource
>>> file and they are assigned to tool buttons
>>> >
>>> >like this:
>>> >
>>> >d_addLayer->setIcon(QIcon(QString::fromUtf8(':/menu_images/plus.png')));
>>> >
>>> >this works great under linux, doesn't work under windows. The QT is
>>> compiled with -qt-libpng
>>> >
>>> >
>>> > Does anyone have clue what's up?
>>> >
>>> >thanks
>>> >d.
>>> >


Message 10 in thread

Uhmmmm! Look like this is the problem. Will have a look.
Thanks

d.