On Wednesday 12 June 2002 18:32, Stephen Green wrote:
> From: Moray Taylor <[EMAIL PROTECTED]>
>
> >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
#
import sys
from qt import *
from qtcanvas import *

class cv(QCanvasView):

    def __init__(self, *args):
        self.canvas = QCanvas(100,100)

        QCanvasView.__init__(self, self.canvas, *args)

        self.item = QCanvasText("bla", self.canvas)
        self.item.move(0,0)
        self.item.show()

        self.canvas.resize(0, 0)
        self.canvas.update()
        self.canvas.resize(100, 100)
        self.canvas.update()

        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    QObject.connect(app, SIGNAL('lastWindowClosed()')
                     , app
                     , SLOT('quit()')
                     )
    win = cv()
    print win.canvas.allItems()
    win.item.setCanvas(None)
    del win.item
    print win.canvas.allItems()
    app.setMainWidget(win)
    win.show()
    app.exec_loop()

Reply via email to