[PyQt] QIODevice+QImageReader oddity ?

Pierre Barbier de Reuille pierre.barbierdereuille at gmail.com
Tue Apr 21 17:14:14 BST 2009


Don't you need to open the device for reading before passing it to QImage ?

For me, just adding:

iop.open(QIODevice.ReadOnly)


makes everything work fine.

-- 
Barbier de Reuille Pierre


2009/4/21 Attila Csipa <pyqt at csipa.in.rs>

> Hello, I'm fairly new to PyQt (have been using Qt from good old C++
> previously) and have a strange issue I did not find a solution to in the
> docs or the archives. In the code snippet below, the image reader works
> if I specify the filename constructor, but not when I try to use it via
> an QIODevice (like QFile or QBuffer). I'm on Ubuntu 9.04, using PyQt
> 4.4.4-2 with Qt 4.5.0-0 (these are the Ubuntu defaults). Am I missing
> something trivial or is this a known issue ? Thanks in advance.
>
> from PyQt4.QtGui import *
> from PyQt4.QtCore import *
>
> def chkerror(reader):
>    if reader.error():
>        print reader.errorString()
>
> iod = QFile("poster_100hours.jpg")
> print iod.size()
>
> #reader = QImageReader("poster_100hours.jpg")
> #reader = QImageReader()
> reader = QImageReader(iod)
> #reader.setDevice(iod)
>
> chkerror(reader)
> print reader.size()
> chkerror(reader)
> img = reader.read()
> chkerror(reader)
> print img.size()
>
>
> ----
> with filename constructor:
> 287998
> PyQt4.QtCore.QSize(1280, 1811)
> PyQt4.QtCore.QSize(1280, 1811)
>
> with QFile iodevice constructor:
> 287998
> PyQt4.QtCore.QSize(-1, -1)
> Invalid device
> Invalid device
> PyQt4.QtCore.QSize(0, 0)
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090421/e3598b46/attachment.html


More information about the PyQt mailing list