wxWindow Destruction order. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

wxWindow Destruction order.

Post by Maeglix »

Hi everyone,

I have this architecture: MyFrame (inherits from wxFrame) which has a child MySplitter (inherits from wxSplitterWindow) which itself has a child LeftWindow (inherits from wxWindow).

For some reasons i would like to be sure that, when i close the app, the LeftWindow is destroyed before the MyFrame.
According to this sentence in the doc: "Please note that all children of the window will be deleted automatically by the destructor before the window itself is deleted which means that you don't have to worry about deleting them manually", i shouldn't have to do anything as the child are destroyed first.

But, when i put a log in the MyFrame's destructor and in the LeftWindow's one I can see that the MyFrame's destructor is called first.

I guess i miss understood something but i don't really see what.

Thanks for your help.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWindow Destruction order.

Post by doublemax »

First the wxFrame dtor is called. Then its wxWindow base dtor will be called. And that one will destroy all its children.
Use the source, Luke!
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: wxWindow Destruction order.

Post by Maeglix »

Oh ok thanks.
Is there a way to add something in the wxWindow base destructor of the Frame ? Because i want to clean some elements when i destroy the frame but i need to be sure that the children are deleted first.
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: wxWindow Destruction order.

Post by Maeglix »

I found something.
I put what i wanted to destroy in the MyApp destructor instead of inside the MyFrame destroctor and it works perfectly.
Post Reply