[PyQt] Not getting it re sip.voidptr

Phil Thompson phil at riverbankcomputing.com
Sun Nov 4 13:02:59 GMT 2012


On Sat, 3 Nov 2012 12:15:21 -0700, David Cortesi <davecortesi at gmail.com>
wrote:
> 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...

I've removed the word "just" as I didn't mean to imply they had the same
APIs.

> 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.

In the same way that a slice of a memoryview returns another memoryview.

> 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.

I can't reproduce this - can you send a short, complete test that
demonstrates the problem.

In tonight's sip snapshot you will be able to pass any object that
implements the Python buffer protocol to sip.voidptr() (like a bytearray).
If nothing else this makes it easier to write tests for voidptr.

Phil


More information about the PyQt mailing list