DO NOT delete QObjects, mmmkay?
Justin Karneges
justin at affinix.com
Thu Nov 8 21:47:21 GMT 2007
On Thursday 08 November 2007 1:17 pm, 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.
Be sure to disconnect signals when you do this, since the object is still
alive and may invoke your slots when you probably expected the object to be
gone.
Also, be aware that calling any method at all on an object during its signal
could be a dangerous thing, since many objects are not written to expect
internal state changes near signal emits:
http://delta.affinix.com/2007/07/18/beyond-signal-safety/
In other words, deleteLater is not a full solution, and the problem is
actually larger and more fundamental. I haven't made a lot of noise about
this issue since I only recently discovered it and I'm still trying to work
out sensible solutions.
-Justin
More information about the kde-core-devel
mailing list