[PySide] QObject.destroyed() is not emitted

Stephan Deibel sdeibel at wingware.com
Thu Nov 29 15:42:43 CET 2012


Alexey Vihorev wrote:
> Ok, let's get less abstract. I got a QTableModel that has to free up some external resources upon its destruction (rollback/close a DB transaction).  In this particular case It's parent is QMdiSubWindow with self.setAttribute(QtCore.Qt.WA_DeleteOnClose), but that is not necessary  - it can be used inside complex widgets, etc.  The code is trivial, but does not work:
>
> class MyModel(QAbstractTableModel):
>
>      def onDestroy(self):
>          #Do some housekeeping
>
>      def __init__(self, entity_cls, parent=None, load=True, criteria=None):
>          ...	
>          self.destroyed.connect(self.onDestroy)
>          ...

Whether or not onDestroy is called in this is entirely dependent on 
whether they are object references to your instance of MyModel somewhere 
else in your code.  It may well be that the parent is holding onto a 
reference after it's closed for some reason (or some other code is), but 
it would be hard to verify this without a complete functional example 
(preferably something pared down as much as possible but still 
exhibiting the issue).

- Stephan




More information about the PySide mailing list