[PyQt] Not getting it re sip.voidptr

David Cortesi davecortesi at gmail.com
Sat Nov 3 19:15:21 GMT 2012


Following up on a stackoverflow answer re manipulating
a QImage, I access the contents of an image by:

    vptr = myQi.bytes()
    vptr.setsize(myQi.byteCount())

Per the Riverbank docs,

> A sip.voidptr may also be given a size... If it has a size then it is
> also able to support Python’s buffer protocol and behaves just
> like a Python memoryview object...

Not being familiar with memoryview I read the docs,
    http://docs.python.org/2.7/library/stdtypes.html#memoryview-type
but I find that my voidptr made as above, does not support any of the
members that type memoryview is supposed to have, such as
readonly(), strides(), ndim(), itemsize(), and especially,
tobytes(). All produce AttributeError.

I can access one byte with vptr[i], but a slice vptr[0:8]
produces only another voidptr object.  When I try assignment,
    vptr[1] = 0x00
I get the message,
    TypeError: 'int' does not have the buffer interface

Clearly there is something I don't get about voidptr and its uses.

This is with python 2.7.6 on ubuntu 12.10, and whatever
levels of Qt4 and PyQt4 I just downloaded with synaptic today.

Thanks for your time,

Dave Cortesi


More information about the PyQt mailing list