[PyKDE] imageformat plugin support in PyQt4?

David Boddie david at boddie.org.uk
Thu Oct 19 12:41:34 BST 2006

On Thu Oct 19 00:32:26 MEST 2006, Tara Hernandez wrote:

> I'm trying to get jpeg image support going via PyQt4, to no luck.  For 
> example, the following C++ code:


>     for (QList<QByteArray>::const_iterator
>         i = formats.constBegin(); i != formats.constEnd(); ++i)
>         cout << string(*i) << "\n";
> returns the expected list:
>     bmp
>     jpeg
>     jpg
>     mng
>     pbm
>     pgm
>     png
>     ppm
>     xbm
>     xpm

OK. I'm guessing that this is with Qt 4.1, but you don't say which platform
you're using.

> But my python code (using the aforementioned Qt distrib) trying to do 
> the same thing skips both jpeg and mng formats:


> print "Supported:"
> for type in QImageReader.supportedImageFormats():
>    print " ",type
> Supported:
>   bmp
>   pbm
>   pgm
>   png
>   ppm
>   xbm
>   xpm


> Everything I've found on the subject says if it's in the C++ side, it 
> should be in the Python side as well, but that really doesn't appear to 
> be the case with regards to plugin supported image formats.

It should work. My installed versions of Qt (4.1.4 and 4.2.0) have plugins
for JPEG and MNG (and SVG in 4.2.0), and these appear in the list of
supported image formats.

> Any clues for me?  Hopefully this is just me missing the appropriate 
> documentation...

Hopefully, you're just seeing the problem described in this post to


Basically, you need to create a QApplication instance before you check
for the available image format plugins.

The reason I didn't see this problem was because I'm using a Python
interpreter with support for Qt's event loop. It creates a QApplication
instance on start-up.

If you still see the same problem after instantiating a QApplication, it's
worth checking that PyQt is built against the same version of Qt that you
used in the first example above, just to eliminate the possibility that
you're looking at different versions of Qt.

Beyond that, I tried to think about various ways in which plugins might not
load but they all seemed quite contrived. If you are still having problems
with this, can you provide some details about your PyQt and Qt


More information about the PyQt mailing list