[PyKDE] QCanvasSprite segfaulting
Phil Thompson
phil at river-bank.demon.co.uk
Thu Feb 27 19:21:01 GMT 2003
On Tuesday 18 February 2003 8:13 am, Vio wrote:
> Greetings,
> Newbie hits wall while dipping toe in QCanvas.
> Would someone be kind enough to tell
> me why I get a segfault while trying to "show()" a sprite?
>
>
> my entire code:
>
> # START OF CODE --------------------------------------------
> #
> # Testing QCanvas
> #
>
> import sys
> from qt import *
> from qtcanvas import *
> TRUE = 1
> FALSE = 0
>
> class MY(QCanvas):
>
> def __init__(self,h = 1000, w=1000):
> QCanvas.__init__(self,h,w)
> self.view = QCanvasView(self)
>
> # testing text
> self.item = QCanvasText('Testosterone',QFont (),self)
> self.item.setX(50)
> self.item.setY(50)
> self.item.show()
>
> # testing sprite
> spix = QCanvasPixmapArray()
> spix.setImage(0,QCanvasPixmap("test.png"))
> sprite = QCanvasSprite(spix, self)
> sprite.move(100, 100, 0)
> sprite.show() #<-- gives Segmentation fault
> # error message:
> #QPixmap::operator=: Cannot assign to pixmap during painting
>
> # Note: if commenting out the "sprite.show()" line, the QCanvasText
> # shows up as expected.
>
>
> # show items on screen
> self.view.show()
> self.update()
>
>
> if __name__ == "__main__":
> a = QApplication(sys.argv)
> QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
> w = MY()
> a.exec_loop()
>
> # END OF CODE --------------------------------------------
The reason that the sprite isn't displayed is because the QCanvasPixmapArray
is being garbage collected. Use "self.spix" instead of "spix".
However, making that simple change still results in a segfault on exit. I can
avoid the segfault by playing with the code (deleting the QCanvas before the
QCanvasView for example) but I'm not sure about the root cause.
I'd be interested to know if the problem persists with a more complete
application - one based on how the canvas.py example does things.
Phil
More information about the PyQt
mailing list