[Qt-interest] Re : crash in destructor of mainwindow?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Tue Jul 13 14:24:41 CEST 2010


BOUCARD Olivier wrote on Monday, July 12, 2010 11:39 AM:

> ...
> But, this can happen when children are not declared in the heap but
> on the stack. 
> If the parent is destroyed after the children get out of their scope,
> it tries to delete already deleted object. 

No, this is NOT a problem: Qt child objects "tell" their parent that they are about to get deleted (either explitily by delete when on the heap or automatically when on the stack), so the parent does NOT try to delete it again (it merely removes it from the list of children internally).

> In addition, call a delete on an address from the stack, its not a
> good idea. 

That is NEVER a good idea, regardless of the framework being in use ;)

But to the OP: are you using DLLs (that is on Windows)? Are the children created in a different address space (that is, you did NOT compile all your projects with the "Multithreaded DLL" switch)? This could be the problem then.

Refer to:
http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx and/or http://msdn.microsoft.com/en-us/library/ms235460.aspx ("Passing CRT Objects Across DLL Boundaries")

In fact I had a similar stack trace with plugins: in my case the problem was that the plugin was unloaded too early, removing the d'tor code from the child out of the address space, so when closing the application the automatic member deletion failed (because the d'tor code was already gone).

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list