I am very interested in this because I have a PySide application where my widgets don't die gracefully (and destroyed isn't signalling their death). I use properties heavily in my code, so I was excited when I saw your email thinking they were the culprit. However, I just tried your example using Python 2.7.1 and PySide 1.1.1, and I can't reproduce the problem. My table prints "destroyed" immediately when I call del m. Are you sure that "property" creates a reference?
I did verify in my environment that onDestroy must be static to function correctly. On Thu, Nov 29, 2012 at 4:40 PM, Christian Tismer <[email protected]>wrote: > Hi friends, > > On 11/29/12 6:37 PM, Stephan Deibel wrote: > > Alexey Vihorev wrote: > >> Thanks, nice find, but... I hit the next hurdle trying to go this > >> way. The signal QObject.destroyed(obj) is passing no arguments > >> (probably because obj is already destroyed), so my static method has > >> nothing to work on. Which kind of devaluates the whole idea, IMHO. > >> And in PyQt4 it*does* pass the object. Even more: in PyQt4 there is > >> no need for static method approach, as it works perfectly with > >> instance methods: > > > > Yea, you would have to bind the necessary data to the callback like this: > > > > def on_destroy(val1=self.whatever, val2=self.something): > > print 'destroyed' > > self.destroyed.connect(on_destroy) > > > > Whether this is possible or useful in your case is of course going to > > depend on the details of the code. > > > > Having 'destroyed' be emitted before the object is destroyed and > > getting the object reference as an arg makes more sense to me. That is > > what PyQt seems to do and it is what QObject does under Qt using C++, > > so I'd call this a bug in PySide. I've added > > https://bugreports.qt-project.org/browse/PYSIDE-129 > > This bug is only half of the story: > > We had that simple @staticmethod work-around. > But actually, the main reason seems to be that PySide suffers > any reference cycle. > > The tiny example again breaks as soon as I add a property: > > {code} > from PySide.QtCore import QAbstractTableModel, QObject > > class MyModel(QAbstractTableModel): > def __init__(self, *args): > super(MyModel, self).__init__(*args) > self.destroyed.connect(self.onDestroy) > > @staticmethod > def onDestroy(): > print('destroyed') > > @property > def hugo(self): > return 42 > > m = MyModel() > del m > {code} > > Remove the @property, and it works, again. > > Rule of thumb: > If you need anything like a property, use a normal Python class > and put your Qt object into it as an attribute. Otherwise your > program will tend to grow in memory ;-) > > Stefan, I added this code to your bug report. > > cheers - chris > > -- > Christian Tismer :^) <mailto:[email protected]> > Software Consulting : Have a break! Take a ride on Python's > Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ > 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de > phone +49 173 24 18 776 fax +49 (30) 700143-0023 > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 > whom do you want to sponsor today? http://www.stackless.com/ > > _______________________________________________ > PySide mailing list > [email protected] > http://lists.qt-project.org/mailman/listinfo/pyside >
_______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
