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