If you create your own hierarchy using QObject s, that is, you initialize all the newly created QObject parent,
QObject* parent = new QObject(); QObject* child = new QObject(parent);
then delete parent enough, because the parent destructor takes care of destroying the child . (He does this by emitting signals, so it is safe even when you delete the child manually in front of the parent.)
You can also remove the child first, the order does not matter. For example, where order matters documentation about object trees .
If your MyClass not a child of a QObject , you will have to use the simple C ++ way of doing things.
Also note that the parent-child QObject hierarchy is usually independent of the hierarchy of the hierarchy tree / C ++ class tree. This means that the assigned child does not have to be a direct subclass of its parent. Any (subclass) of QObject will suffice.
However, there may be some restrictions imposed by designers for other reasons; for example, in QWidget(QWidget* parent=0) , where the parent must be a different QWidget , due to, for example, visibility flags and because you are doing the basic layout in this way; but for the Qt hierarchy system as a whole, you can have any QObject as a parent.
Debilski Mar 22 '10 at 11:33 2010-03-22 11:33
source share