Re: [PyKDE] How do I delete a QCanvasItem?
Stephen Green wrote: Ok, I think I found out what causes the problem in my code. Here is a small part of my program that will crash. As it is, if you create a point in the program, then delete the point, then try to create a new point, it usually gives a segmentation fault. But if you comment lines 14 and 18, it works fine (but it still sometimes doesn't quit properly). These lines add a second frame to the QCanvasSprite (they make it so that the color can be changed). Does this crash for you guys too, or is it just me? And should I not be creating other frames in this way? I could probably make the points out of QCanvasEllipses instead, and change the brush, but I'd still like to figure out what's going wrong here. I'm using Python 2.2, SIP 3.2.1, PyQt 3.2.1, and Qt 3.0.3, on Red Hat 7.3. This is now fixed in today's snapshot. Phil ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
Ok, I think I found out what causes the problem in my code. Here is a small part of my program that will crash. As it is, if you create a point in the program, then delete the point, then try to create a new point, it usually gives a segmentation fault. But if you comment lines 14 and 18, it works fine (but it still sometimes doesn't quit properly). These lines add a second frame to the QCanvasSprite (they make it so that the color can be changed). Does this crash for you guys too, or is it just me? And should I not be creating other frames in this way? I could probably make the points out of QCanvasEllipses instead, and change the brush, but I'd still like to figure out what's going wrong here. I'm using Python 2.2, SIP 3.2.1, PyQt 3.2.1, and Qt 3.0.3, on Red Hat 7.3. _ Send and receive Hotmail on your mobile device: http://mobile.msn.com test.py Description: Binary data
Re: [PyKDE] How do I delete a QCanvasItem?
On Friday 14 June 2002 19:31, Stephen Green wrote: Ok, I think I found out what causes the problem in my code. Here is a small part of my program that will crash. As it is, if you create a point in the program, then delete the point, then try to create a new point, it usually gives a segmentation fault. But if you comment lines 14 and 18, it works fine (but it still sometimes doesn't quit properly). These lines add a second frame to the QCanvasSprite (they make it so that the color can be changed). Does this crash for you guys too, or is it just me? And should I not be creating other frames in this way? I could probably make the points out of QCanvasEllipses instead, and change the brush, but I'd still like to figure out what's going wrong here. Yes, I've got a segfault, too. -- Boudewijn Rempt | http://www.valdyas.org ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
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()
Re: [PyKDE] How do I delete a QCanvasItem?
From: Boudewijn Rempt [EMAIL PROTECTED] To: Stephen Green [EMAIL PROTECTED] CC: [EMAIL PROTECTED] 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 [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 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 worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
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 ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
Moray Taylor wrote: 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? Yes - I'd forgotten I'd already taken care of this. If you look at the implementation of QCanvasItem.setCanvas() in qcanvas.sip, ownership is transferred to C++ if the item is now allocated to a canvas and transferred back to Python if it is not now allocated to a canvas. Obviously, once ownership is back with Python the C++ dtor will get called when the Python object is garbage collected. Phil ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
On Monday 10 June 2002 21:29, Stephen Green wrote: I've been trying to figure out how to delete a QCanvasItem from a QCanvas. I tried using del, QCanvas.removeChild() and removing all references to it. None of this works though. I think removeChild() doesn't work because it takes a QObject as input, but QCanvasItem does not inherit QObject. Does anybody know how to do this? I've just experimented a bit, and I found that canvas items just don't disappear. I think that's a bug. The only sure way of making items disappear currently is to hide() them, and that could lead to prodigious memory leaks. # # 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) item = QCanvasText(bla, self.canvas) item.move(0,0) 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() # __init__ has run, so item should be # dereferenced. app.setMainWidget(win) win.show() app.exec_loop() -- Boudewijn Rempt | http://www.valdyas.org ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde
Re: [PyKDE] How do I delete a QCanvasItem?
Boudewijn Rempt wrote: On Monday 10 June 2002 21:29, Stephen Green wrote: I've been trying to figure out how to delete a QCanvasItem from a QCanvas. I tried using del, QCanvas.removeChild() and removing all references to it. None of this works though. I think removeChild() doesn't work because it takes a QObject as input, but QCanvasItem does not inherit QObject. Does anybody know how to do this? I've just experimented a bit, and I found that canvas items just don't disappear. I think that's a bug. The only sure way of making items disappear currently is to hide() them, and that could lead to prodigious memory leaks. Thanks for doing the experiments. I plan to implement a method in the SIP Python module that will provide direct access to the C++ dtor for the rare cases (of which this is probably the only one in PyQt) where the API being wrapped is lacking. The reason that I haven't done it yet is that the SIP module will be renamed in the near future from libsip to sip, so if I add methods now I will soon be breaking them. Would you prefer to see libsip.sipCallDtor() in SIP v3.3 or can you wait for sip.sipCallDtor() in SIP v4.0? Phil ___ PyKDE mailing list[EMAIL PROTECTED] http://mats.gmd.de/mailman/listinfo/pykde