[PyKDE] How do I delete a QCanvasItem?

Stephen Green estebanverde at hotmail.com
Wed Jun 12 23:57:01 BST 2002



>From: Boudewijn Rempt <boud at valdyas.org>
>To: "Stephen Green" <estebanverde at hotmail.com>
>CC: pykde at mats.gmd.de
>Subject: Re: [PyKDE] How do I delete a QCanvasItem?
>Date: Wed, 12 Jun 2002 22:08:59 +0200
>
>On Wednesday 12 June 2002 18:32, Stephen Green wrote:
> > From: Moray Taylor <mtaylor at lowebroadway.com>
> >
> > >I think I have figured out how to do it.
> > >
> > >MyCanvasItem.setCanvas(None)
> > >
> > >It gets rid of it, and seems to free any memory it was using.
> > >
> > >Any comments?
> > >
> > >Moray
> >
> > I tried doing that, and it seems to make the canvas item disappear, but
> > shortly thereafter I always get a segmentation fault.  I can't figure 
>out
> > why this is happening, since I'm pretty sure I've removed all references 
>to
> > the canvas item.
> > Any ideas?
> >
>
>If I simply add
>
>	item.setCanvas(None)
>
>after item.show() in the test script I posted earlier, I don't get a
>segfault. It's quite possible that my script is too simple, and that the
>segfault occurs only under more complex circumstances. Could you run the
>attached file, and see if it segfaults for you?
>
>--
>Boudewijn Rempt | http://www.valdyas.org
><< canvas.py >>


Yeah, your code works fine for me. I don't know what the problem is then.

Right now, to delete an item from the canvas, I'm doing the following inside 
my canvas class:

def deleteObject(self, x):
    x.setCanvas(None)
    self.items.remove(x)
    del x
    self.update()

Actually it's a bit more complicated than that, but that's the main part.  
Maybe you're right that the segfault only occurs in more complex code...

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




More information about the PyQt mailing list