[Qt-interest] Is child object guaranteed to be delete when its parent destroy?
Kermit Mei
kermit.mei at gmail.com
Sat Mar 28 04:34:47 CET 2009
Hello community!
I always consider that if a parent object calls deleteLater(), then all
of its children will delete automatically. But I can't understand what I
encouterred today. To represent it simply, for example:
A,B,C are all QWidget's sub-classes, and they are different. Now, in
the defination of A's method, I create a B's object:
A::fooA() {
pB = new B(this);
}
And later, I pass pB to a QStackedWidget's Object, and add it to the
stacked-object. After I finishing my work with A's object, I want to
delete A's object, and I called object->deleteLater(). I can see that A
is deleted by the debug infomation, and remove from the stacked-obect
automatically. But, the B's object which pointed by pB is not deleted,
ant it is also in the stackedWidget.
I know I can delete it in ~A(), but I wonder to know why it can't delete
it self when A was deleted? It is a child of, isn't it?
How can I understand it?
Thanks.
Kermit
More information about the Qt-interest-old
mailing list