PDA

View Full Version : loadFromData with Pixmap probelm



December
10th June 2008, 16:38
Hi All,

Part of my program loads an image (a jpg) from the web and displays it on a QLabel.

This is the important bit of code;



pixmap->loadFromData( buffer->buffer() );
labelIcon->setPixmap( *pixmap );


Now, this seems to work great on Linux, but not at all on Windows. I wrote the data in the buffer out to a file on both Linux and Windows and they are identical files. They show fine in all the image viewers I tried. I also tried with a a few different images from the web to make sure it was not a problem with onc specific image.

Next thing I tried was writing the buffer to a temporary file and re-loading it into the pixmap using pixmap->load( filename ). This worked great on Linux, and again not on Windows.

I know there was a similar thread before, and the conclusion was that it was a bug in QT, but when I checked that bug on the Trolls site, it was listed as Rejected (verified as working on all platforms).

Can anyone make a suggestion as to where I am might be going wrong, or a work-around I could use to get this working in Windows?

I tried with QT 4.3.2 and then 4.3.5 on Windows
Am using QT 4.3.4 on Linux.

jacek
11th June 2008, 00:24
What does QImageReader::supportedImageFormats() return on windows?

December
12th June 2008, 14:25
Oh damn. I just assumed it supported JPG since in the docs it states:

By default, Qt can read the following formats:

BMP
GIF
JPG
JPEG
MNG
PNG
PBM
PGM
PPM
TIFF
XBM
XPM

Hmm, going to have to figure out how to convert it of its a jpeg then I guess. Can anyone point me to some code to do JPG -> PNG conversion?

jacek
12th June 2008, 14:48
Hmm, going to have to figure out how to convert it of its a jpeg then I guess. Can anyone point me to some code to do JPG -> PNG conversion?
AFAIR the JPEG support is compiled as plugin on windows. So first check if you have the QJPEG plugin compiled. If yes, then it's just a matter of placing it imageformats subdirectory in the directory where the executable is. If not, you will have to reconfigure and recompile Qt (you can do it also to compile QJPEG into Qt).

December
12th June 2008, 15:25
I just tried this:

configure -qt-libjpeg -static
make subsrc

But JPG is still not showing up.

Also tried moving qjpeg4.dll into the same folder as the exe, still no JPG support.

jacek
12th June 2008, 23:16
configure -qt-libjpeg -static
Hmm... I've just checked configure's options and it seems that you can't compile QJPEG into Qt anymore.


Also tried moving qjpeg4.dll into the same folder as the exe, still no JPG support.
Create "imageformats" subdirectory in that folder and move qjpeg4.dll there.

Iff you use static Qt, you will have to add "QTPLUGIN += qjpeg" to your .pro file and "Q_IMPORT_PLUGIN(qjpeg)" before main().