User forums > Using Code::Blocks
How to implement inheritance of custom frames (wxSmith MDI app)
kathbeau:
I am new to Code::Blocks, and am using wxSmith to develop a test MDI application.
I want to create a form hierarchy such as this:
BaseChildFrame (derives from wxMDIChildFrame)
* contains a wxBoxSizer, which
* contains a wxPanel
It will also contain code that can be invoked from forms that derive from it.
Here's where I went off the rails:
From the wxSmith tab, I selected Add wxFrame, and opened the Advanced options. Changed Base class name to my BaseChildFrame, but otherwise left everything unchanged.
Then I clicked OK. I modified the constructor to take BaseChildFrame* for the parent argument, and hoped to see that my sizer and panel had been brought into the new form/frame as inherited objects. This did not happen, and of course the whole mess does not compile. (I come from long years using the Borland Visual Component Library, which is where I got my expectations.)
I don't see the matter of inheritance for forms covered in the wxSmith tutorials, nor was online searching for combinations of keywords "wxWidgets", "wxSmith", "frame", "inheritance" fruitful.
Hoping somebody can point me to documentation (would love a tutorial or example).
Thanks,
Kathleen
boya:
You did not state your compiling error, so I am not sure how you have modified the constructor of the derived class. Let me guess the compiling error is something like this:
--- Quote ---error: expected class-name before '{' token|
--- End quote ---
or
--- Quote ---In constructor 'NewFrame::NewFrame(BaseChildFrame*, wxWindowID, const wxPoint&, const wxSize&)':
error: no matching function for call to 'BaseChildFrame::BaseChildFrame()'
--- End quote ---
If the first situation exists, then you should include the header file of the class BaseChildFrame in NewFrame.h;
If the second does, you should correct NewFrame.cpp as below:
--- Code: ---NewFrame::NewFrame(wxWindow*, wxWindowID, const wxPoint&, const wxSize&)
: BaseChildFrame(parent)
--- End code ---
Moreover, the call to "Create()" in this constructor, which is generated by wxSmith, should be removed (e.g. add //), otherwise application does not quit on closing this frame.
Then you can call this NewFrame like this:
--- Code: ---NewFrame* Frame = new NewFrame(0);
Frame->Show();
--- End code ---
or in an existing window:
--- Code: ---NewFrame* Frame = new NewFrame(this);
Frame->Show();
--- End code ---
My test case is OK through these modifications, on Windows 7 with CodeBlocks svn 10035.
The cause of the second situation is that the base class does not have a default constructor, and that it does not get initialised explicitly.
kathbeau:
Thank you, Boya!
Following your guidelines, I now have a wxMDIParentFrame with a menu, where I have added a menu item to create a new wxMDIChildFrame. That child window follows this hierarchy:
class BasicFrame : public wxMDIChildFrame
* contains wxBoxSizer, which contains
* wxPanel, with properties (including background color) adjusted
class BasicMenuFrame : BasicFrame
* added a frame-specific menu (just to see what would happen)
When I build and run the app, and invoke the menu item, I see the form has my color-modified panel (first child feature) and a menu (second child feature), so the inheritance is working.
Unfortunately, this inheritance does not display in the C::B IDE. That is, if I want to start adding sizers and widgets to the wxPanel that was inherited from the first child frame, it is not represented in the second (derived) child.
Oh, and now I've totally trashed my project. (heavy sigh)
Anyway, I do thank you so much for getting me this far! If you can help me with the IDE issue, I should be able to go off on my own for a little while.
Kathleen
kathbeau:
--- Quote from: boya on December 02, 2014, 01:04:53 pm ---If the second does, you should correct NewFrame.cpp as below:
--- Code: ---NewFrame::NewFrame(wxWindow*, wxWindowID, const wxPoint&, const wxSize&)
: BaseChildFrame(parent)
--- End code ---
Moreover, the call to "Create()" in this constructor, which is generated by wxSmith, should be removed (e.g. add //), otherwise application does not quit on closing this frame.
--- End quote ---
Another problem: Each time I modify the inherited .wxs, the "Create(..." is uncommented. Obviously, I can just comment it out again, but in a large and changing project this could get to be really annoying.
oBFusCATed:
Probably there is a bug in wxSmith. Patches welcome.
Navigation
[0] Message Index
[#] Next page
Go to full version