wxFormBuilder code generation

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
NoguSvelo
In need of some credit
In need of some credit
Posts: 1
Joined: Tue May 25, 2021 9:39 am

wxFormBuilder code generation

Post by NoguSvelo »

Hello.
I use wxFormBuilder to generate C++ code for many of my projects for MSW, but one thing has been bugging me for a long time.
This is what the tool generates for a simple button-on-a-form project:

Code: Select all

MyFrame2::MyFrame2( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );

	wxBoxSizer* bSizer3;
	bSizer3 = new wxBoxSizer( wxVERTICAL );

	m_button2 = new wxButton( this, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer3->Add( m_button2, 0, wxALL, 5 );

	this->SetSizer( bSizer3 );
	this->Layout();
	this->Centre( wxBOTH );
}

MyFrame2::~MyFrame2()
{
}
So the builder creates objects on the heap, using new operator, but the frame destructor is empty o.O
Does the memory ever gets freed and controls' destructors get called?
My working theory is that one of the frame parent's destructors destroys assigned via SetSizer sizer, which destroys every control added to it using Add.
Can anyone confirm that this is correct?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxFormBuilder code generation

Post by PB »

Yes, child windows and sizers are deleted automatically. See https://docs.wxwidgets.org/stable/overv ... n_deletion

BTW, I would not learn wxWidgets from a code generated by wxFB. I would consider that write only code.
Post Reply