[PyQt] Confusion about const & non-const QImage constructors from raw data

TP wingusr at gmail.com
Fri Feb 19 12:31:36 GMT 2010


In http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg18113.html
Phil Thompson was asking about the non-const QImage constructor:

  QImage(uchar *data, int width, int height, int bytesPerLine, Format format);

and suggested implementing it using "void *" as the first argument.
However, when I
look at the online doc for PyQt's Qimage() class at
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qimage.html#QImage-6
I see these two constructors:

 QImage.__init__ (self, str, int, int, int, Format)

 QImage.__init__ (self, sip.voidptr, int, int, int, Format)

  Unlike the similar QImage constructor that takes a non-const data
  buffer, this version will never alter the contents of the
  buffer. For example, calling QImage.bits() will return a deep copy
  of the image, rather than the buffer passed to the constructor. This
  allows for the efficiency of constructing a QImage from raw data,
  without the possibility of the raw data being changed.

So it appears the sip.voidptr version is the const version?

I want to use the non-const version, but don't know how to get a str
as the first argument? If I have the address of my image raw data, how
do I convert that to a str that QImage.__init__ (self, str, int, int,
int, Format) will accept?


More information about the PyQt mailing list