DO NOT delete QObjects, mmmkay?

Andreas Pakulat apaku at gmx.de
Thu Nov 8 21:48:39 GMT 2007


On 08.11.07 23:32:34, Diego Iastrubni wrote:
> Aaron J. Seigo wrote:
>> On Thursday 08 November 2007, Andreas Hartmetz wrote:
>>   
>>> All in all I have fixed three or four crashes in various KDE modules where
>>> QObjects were deleted while a signal/slot call involving that QObject was
>>> going on.
>>>     
>>
>> p.s. the usual solution when you need to have a QObject deleted is to call 
>> deleteLater() on the object instead of delete'ing it with the C++ keyword.
>>
>> p.p.s. the QObject::destroyed(QObject*) signal can be very handy at times, 
>> too.
>>   
> Yes, but be warned, that signal is emitted *after* the QObject has been 
> deleted.

Thats not quite right, see
http://doc.trolltech.com/4.3/qobject.html#destroyed

However the signal is emitted from the destructor so anything from your
QObject subclass is probably destroyed at that already. Anything from
the QObject class itself should still be available.

Andreas

-- 
Your best consolation is the hope that the things you failed to get weren't
really worth having.




More information about the kde-core-devel mailing list