[PySide] QObject.destroyed() is not emitted
Félix C. Morency
felix.morency at gmail.com
Wed Nov 28 15:37:18 CET 2012
I've seen this before. Try a throw instead of a print and see if its called.
Also, try to del your object as Stephan mentioned.
On Wed, Nov 28, 2012 at 9:33 AM, Stephan Deibel <sdeibel at wingware.com>wrote:
> Alexey Vihorev wrote:
> > Got problems with the following code:
> > from PySide import QtCore
> > def onDestroy(*args):
> > print('destroyed')
> > obj = QtCore.QObject()
> > obj.destroyed.connect(onDestroy)
> > The onDestroy() method is not called, unless del(obj) is called
> > explicitly. In PyQt4 it is called without del(obj). Is that a bug or
> > intended behavior? I’m using Qt 4.8.2, PySide 1.1.2 32bit, Windows 7-64
> Since no one responded I'll take a stab at this:
> I suspect the life cycle of the QObject under PySide is a little
> different and the instance will be deleted later during garbage
> collection and not immediately when it goes out of scope. I'm actually
> not sure why that is happening in PyQt (seems slightly surprising).
> In general if you want to make sure an instance is deleted at a
> particular moment in time, you need to delete it explicitly. By that, I
> mean calling some sort of delete method (in PySide I think it's
> shiboken.delete(obj) and not just "del obj". The latter just deletes
> your reference to the instance but doesn't destroy the instance until
> all other references are gone and it is garbage collected. Of course
> calling shiboken.delete(obj) will be a problem if you still have other
> references and try to use them!
> There is also obj.deleteLater() which marks an object for deletion but
> it's not deleted until the event loop is reached again. Depending on
> what you're doing this may be a safer way to delete it.
> At first I thought this might be a refcount bug in PySide. However, I'm
> thinking not since "del obj" just deletes your reference to it and if
> there were extra references hanging around (either on purpose or as a
> result of a refcount bug) then it would not be deleting the instance at
> all even after "del obj".
> I don't understand PySide internals that well so it's possible I'm
> missing some subtlety here. I'm going more on my knowledge of Python in
> - Stephan
> PySide mailing list
> PySide at qt-project.org
Félix C. Morency, M.Sc.
Plateforme d’analyse et de visualisation d’images
Centre Hospitalier Universitaire de Sherbrooke
Centre de recherche clinique Étienne-Le Bel
Local Z5-3031 | 819.346.1110 ext 16634
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide