Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, August 2007
Destructor Order


Message 1 in thread

I have a main window with four child widgets.  I created it in
Designer.  Qt 4.2.2

How do I control the order that the child widgets get destroyed?

Thanks in advance...
-Willy

--
 [ signature omitted ] 

Message 2 in thread

On Wednesday 01 August 2007, Willy P wrote:
> I have a main window with four child widgets.  I created it in
> Designer.  Qt 4.2.2
>
> How do I control the order that the child widgets get destroyed?

You could define an own constructor for your main window and then manually 
delete the child widgets in the wanted order.

-- 
 [ signature omitted ] 

Message 3 in thread

"Willy P" <willy.lists@xxxxxxxxx> wrote in message 
news:3dd63f0708010154p1a94b880hd28e02d5ab0af7e4@xxxxxxxxxxxxxxxxx
>I have a main window with four child widgets.  I created it in
> Designer.  Qt 4.2.2
>
> How do I control the order that the child widgets get destroyed?
>
> Thanks in advance...
> -Willy

Just delete them yourself in your favourite order.

Qt will delete them in the inverse order in which they appear in their 
children-list (which is by default the order of creation, unless you can 
raise() and lower() on them as this shifts their position in the 
children-list).

Volker


--
 [ signature omitted ] 

Message 4 in thread

"Volker Hilsheimer" <unwatched@xxxxxxx> wrote in message 
news:f8q7i6$ecb$1@xxxxxxxxxxxxxxxxxxxxx

> Just delete them yourself in your favourite order.
>
> Qt will delete them in the inverse order in which they appear in their 
> children-list (which is by default the order of creation, unless you can 
> raise() and lower() on them as this shifts their position in the 
> children-list).

Is it necessary then to set them to 0 to prevent double
deletion problems or is there some magic involved? 


--
 [ signature omitted ] 

Message 5 in thread

On 8/1/07, Duane Hebert <spoo@xxxxxxxxx> wrote:
>
> "Volker Hilsheimer" <unwatched@xxxxxxx> wrote in message
> news:f8q7i6$ecb$1@xxxxxxxxxxxxxxxxxxxxx
>
> > Just delete them yourself in your favourite order.
> >
> > Qt will delete them in the inverse order in which they appear in their
> > children-list (which is by default the order of creation, unless you can
> > raise() and lower() on them as this shifts their position in the
> > children-list).
>
> Is it necessary then to set them to 0 to prevent double
> deletion problems

Not necessary. The pointer variables you keep around do not influence
Qt's automatic cleanup. Qt doesn't know about your pointer variables,
so it couldn't use them.

> or is there some magic involved?

It's not really magic. QObjects keep track of their children, so
parents automatically delete their children when they are deleted. If
a child object is deleted "early", its destructor notifies its parent
and the parent removes that object from its list of children so it
doesn't later attempt to delete an object that's already been
destroyed.

-- 
 [ signature omitted ] 

Message 6 in thread

"Andrew Medico" <a.medico@xxxxxxxxx> wrote in message 
news:c8ec85e70708011203v17d466ecl67bb12a501eca06e@xxxxxxxxxxxxxxxxx
> On 8/1/07, Duane Hebert <spoo@xxxxxxxxx> wrote:
>>
>> "Volker Hilsheimer" <unwatched@xxxxxxx> wrote in message
>> news:f8q7i6$ecb$1@xxxxxxxxxxxxxxxxxxxxx
>>
>> > Just delete them yourself in your favourite order.
>> >
>> > Qt will delete them in the inverse order in which they appear in their
>> > children-list (which is by default the order of creation, unless you 
>> > can
>> > raise() and lower() on them as this shifts their position in the
>> > children-list).
>>
>> Is it necessary then to set them to 0 to prevent double
>> deletion problems
>
> Not necessary. The pointer variables you keep around do not influence
> Qt's automatic cleanup. Qt doesn't know about your pointer variables,
> so it couldn't use them.
>
>> or is there some magic involved?
>
> It's not really magic. QObjects keep track of their children, so
> parents automatically delete their children when they are deleted. If
> a child object is deleted "early", its destructor notifies its parent
> and the parent removes that object from its list of children so it
> doesn't later attempt to delete an object that's already been
> destroyed.

That's good to hear.  Coming from Borland stuff, we were limited
in using std containers and such for VCL objects.  Clearing a vector
of TObjects in a dtor (automatically) would likely crash when the parent
try to cleanup later.  I know that I haven't had these sorts of problems 
with
Qt but I wasn't sure if it was just luck. 


--
 [ signature omitted ] 

Message 7 in thread

Thanks for all the responses.  I have 4 pointers to child widgets as
members of the main window widget class.  Changing the declaration
order and the order they are added to the main window widget doesn't
change the order they are deleted.  Neither does raise() and lower().
Any ideas as to why this is the case?

Thanks again...
-Willy

On 8/1/07, Volker Hilsheimer <unwatched@xxxxxxx> wrote:
> "Willy P" <willy.lists@xxxxxxxxx> wrote in message
> news:3dd63f0708010154p1a94b880hd28e02d5ab0af7e4@xxxxxxxxxxxxxxxxx
> >I have a main window with four child widgets.  I created it in
> > Designer.  Qt 4.2.2
> >
> > How do I control the order that the child widgets get destroyed?
> >
> > Thanks in advance...
> > -Willy
>
> Just delete them yourself in your favourite order.
>
> Qt will delete them in the inverse order in which they appear in their
> children-list (which is by default the order of creation, unless you can
> raise() and lower() on them as this shifts their position in the
> children-list).
>
> Volker
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ]