[PyKDE] QCanvasSprite and QPixmapArray scope issues

Alexander Borghgraef alexander.borghgraef.rma at gmail.com
Fri Apr 28 13:27:53 BST 2006


Hi all,

 I'm writing an interface for displaying and processing sequences of images.
I'm using QCanvasSprites to
contain and animate the sequences. My first implementation worked, but when
I cleaned it up a bit, I got
segmentation faults. The problem appeared to be that QCanvasSprite takes a
QPixmapArray for parameter,
but that the sprite doesn't seem to manage the array's memory. So when I
wrote a gui class a bit like this:

  class MyGui( QMainWindow ):
    def __init__( self ):
      ...
      self.canvas = QCanvas( 200, 200 )
      self.seqView = QCanvasSprite( QPixmapArray( listOfQPixmap ),
self.canvas )

I got a segmentation fault as soon as the program exited MyGui.__init__,
most likely the first time the gui tried to
refresh the sprite. Same thing with:

      ...
      pixArray = QPixmapArray( listOfQPixmap ),
      self.seqView = QCanvasSprite( pixArray , self.canvas )

What fixed it was this:
      ...
      self.pixArray = QPixmapArray( listOfQPixmap ),
      self.seqView = QCanvasSprite( self.pixArray , self.canvas )

Why is this? Logically, QCanvasSprite should hold a pointer towards the
pixmap array, so even if the variable
goes out of scope, the sprite should still point to the array, shouldn't it.
It works that way with QCanvas: you
can for example do this:

      self.canvas = QCanvas( 200,200 )
      QCanvasRectangle( 20, 20, 30, 40, self.canvas ).show()

While the QCanvasRectangle goes out of scope, it still remains accessible
through the self.canvas variable: it
remains visible and you can access it for instance through
QCanvas.allItems()[0].
Why doesn't QCanvasSprite
follow this logic? Is my third example the right way of using the class, or
are there better options? Or did I miss
something obvious? I'm using python 2.3, Qt 3.3.3, and PyQt 3.13

--
Alex Borghgraef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060428/056aa537/attachment.html


More information about the PyQt mailing list