Unexpected crash upon application exit
-
In an earlier question I asked about resource management with Qt, and in particular about the RAII principle (see: http://forum.qt.io/topic/61842/how-can-i-ensure-proper-resource-management-raii-when-using-qt-plugins).
In one of the answers it was mentioned that in theory with Qt it is not necessary to think about this too much, because Qt internally keeps track of the lifetime of
QObject
s.I created a very small code snippet that seems to indicate the opposite: http://paste.ubuntu.com/15347864/.
Running this snippet causes anullptr
-exception in qscopedpointer.h on line 112 (the line number is for Qt 5.6.0 beta, on hash 38e602d0f). Allthough I'm referring to Qt 5.6, I noticed the same problem already in Qt 5.4.Did I stumble on a subtle, yet important bug, or did I something 'illegal'?
-
@Jakob
Switch the order of the construction of objects. When theparent
's destructor runs it'll try to free its children, but since you've created it after the child (hence its destructor will be called first), it will try todelete
a stack object.