Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Doubt about deleting a child QObject
fluca1978 last edited by
imagine I've got class A that inherits QObject and that creates an instance of class B, which inherits from QObject too, attaching himself as parent, so that B (instance) has A (instance) as parent. Now imagine that A performs an explicit delete on B (instance). What happens when A is deleted too? I mean, could the explicit deletion cause some sort of problems or the Qt is simply passing thru the no-more valid B pointer/reference? I imagine the latter, but it is just to be sure.
Zlatomir last edited by
No, there is no problem in the situation you described, the child delete itself from it's parent's list of children.
There is an issue if the child is allocated on stack and the parent gets deleted first: in this case parent calls delete on an address of a stack allocated object.
//see "this":http://doc.qt.nokia.com/4.7-snapshot/objecttrees.html doc page