[Interest] QObject.destroyed() not working?!
Thiago Macieira
thiago.macieira at intel.com
Mon Mar 27 08:48:16 CEST 2017
On domingo, 26 de março de 2017 18:52:48 PDT Frank Rueter | OHUfx wrote:
> Hi,
>
> I'm pretty sure I'm misinterpreting how this should work so maybe you
> guys can help:
>
> I have a QObject which I would like to run a simple clean up job just
> before it's destroyed.
> I thought I could simply do this in it's constructor:
> self.destroyed.connect(self.__cleanUp)
>
> Then have self.__cleanUp() to the work.
> However, a simple print statement inside self.__cleanUp() shows that
> it's never run.
I don't speak Python, so I am answering in terms of C++:
QObject::destroyed() is emitted from QObject's own destructor. That means the
object, at the time, *IS* a QObject and not your class. There is no slot
called "__cleanUp" at that time anymore.
destroyed() is useful for another QObject to perform some actions, not for the
same object. If you need some actions to be performed at the time of
destruction, just put them in your class's destructor.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list