[Qt-interest] Is child object guaranteed to be delete when its parent destroy?
Kermit Mei
kermit.mei at gmail.com
Sat Mar 28 13:08:41 CET 2009
On Sat, 2009-03-28 at 09:13 +0100, Andreas Pakulat wrote:
> On 28.03.09 11:34:47, Kermit Mei wrote:
> > 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.
>
> With that you're giving away pB to the stackwidget. The stackwidget
> takes ownership of the widgets in its stack, so the parent of pB is
> changed to be the stackwidget.
>
> > 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?
>
> Because A is not the parent anymore.
>
> Andreas
Yes, I see. Thanks;p
More information about the Qt-interest-old
mailing list