[PyKDE] QCanvas again

Phil Thompson phil at river-bank.demon.co.uk
Wed Oct 4 18:38:12 BST 2000

Philippe Fremy wrote:
>         Hi,
> New problem with the QCanvasSprite.
> I use the constructor
> QCanvasSprite( QCanvasPixmapArray * array, QCanvas * canvas).
> What qt does with the QCanvasPixampArray is only storing the pointer. This is
> ok in C++ but not in Python, because the array gets deleted at the end of my
> assigning function.  When I want to show the QCanvasSprite, I get a segfault.

This is a common issue and is covered in the PyQt docs.

> My workaround was simply to have a global list that holds a reference to all
> QCanvasPixmapArray being used. But I think the PyQCanvas should itself
> increase the reference count of the array, so that it doesn't get deleted.

That is the correct workaround. While its possible to do as you suggest
for this case, there are other more complicated cases where it creates
more problems than it solves. After experiences in earlier versions of
PyQt where reference counts are increased under the covers, I now have
an unwritten rule that bindings don't change reference counts. I do
agree, though, that it would be nice in this particular case.


More information about the PyQt mailing list