Code::Blocks Forums

User forums => Help => Topic started by: Danishx83 on May 03, 2012, 06:21:02 pm

Title: redefinition of wxFrame & wxApp
Post by: Danishx83 on May 03, 2012, 06:21:02 pm
I am trying wxWidgets ( 2.8 ) on C::B ( 10.5 ), created a new project, setup every thing as shown by many guides / tutorials. When I try to compile, it gives two warnings


in  wxMain.h

Code
class wxFrame : public wxFrame {
  //constr
  //distor
  //few funct
  //few static const
  //a pointer
};

in wxApp.h

Code
class wxApp : public wxApp {
  //OnInit function
};

All the code is auto generated, as I am just starting to learn wxWidgets
Title: Re: redefinition of wxFrame & wxApp
Post by: oBFusCATed on May 03, 2012, 06:25:34 pm
Isn't it obvious?
Your derived class must not have the same name as the base class. Rename wxFrame to something else and it will be fine.
I guess you'll have to run the wxsmith wizard once again...
Title: Re: redefinition of wxFrame & wxApp
Post by: Danishx83 on May 03, 2012, 06:58:32 pm
Yes I tried that before but there were many more errors,  :-[

Now I changed them again

in  wxMain.h

Code
class MywxFrame : public wxFrame {
  //constr MywxFrame
  //distor MywxFrame
  //few funct
  //few static const
  //a pointer
};

in wxMain.cpp
respective changes


in wxApp.h

Code
class MywxApp : public wxApp {
  //OnInit function
};

in wxApp.cpp
respective changes

The thing that made it work was changing

Code
BEGIN_EVENT_TABLE(wxFrame, wxFrame){} //error (auto generated code)
to
Code
BEGIN_EVENT_TABLE(MywxFrame, wxFrame){} //Correct
which previously I did was
Code
BEGIN_EVENT_TABLE(MywxFrame, MywxFrame){} //error

in wxMain.cpp

So all this implies that the auto generated code has error, how do I correct it, so next time I create a new project and don't have to do all this.
Title: Re: redefinition of wxFrame & wxApp
Post by: oBFusCATed on May 03, 2012, 07:50:05 pm
Please explain all the step you take to make a new project.
You've made an error somewhere and this will help us see what you're doing wrong.

Editing the existing project is a bit pointless. You can replace all the references to wxFrame and wxApp in the wxs files created by the wizard.
But this is not needed and creating project should work out of the box.
Title: Re: redefinition of wxFrame & wxApp
Post by: Danishx83 on May 03, 2012, 08:27:22 pm
File > New > Project
wxWidgets
wxWidgets 2.8.x
Project title "wx" <-------------Problem creator :o, caught it, but the template must cater for newbies like me
Auth Name "danishx83"
PrefGUIbuild -> wxSmith, Apptype -> FrameBased
wxWidgets Loc-> $(#wx) = "C:\wxWidgets2.8"
Compiler-> MinGW, Debug = Yes, Release = Yes
wxWidgetsLibSet-> Use DLL = Yes, monolithic = Yes, Unicode = Yes
Misc -> PCH = Yes

Files
wxApp.cpp
wxMain.cpp
wx_pch.h
wxApp.h
wxMain.h
resources.rc
xframe.wxs


@oBFusCATed: Thank You

Title: Re: redefinition of wxFrame & wxApp
Post by: Jenna on May 04, 2012, 05:03:39 pm
Project title "wx" <-------------Problem creator :o, caught it, but the template must cater for newbies like me
I don't think so, sorry,  but there is no way to check for all possible redefinitions in all toolkit we have wizards for.
Title: Re: redefinition of wxFrame & wxApp
Post by: Danishx83 on May 06, 2012, 07:43:52 pm
the problem is that when I named my project as "wx", it created the class wxFrame for my application and was trying to extend the project wxFrame with base class wxFrame. I think a simple solution to it would be to append a "_" or some char between the project name and object type (Frame, Dialog etc) so that no project name could ever replicate the original base class identifiers.
Title: Re: redefinition of wxFrame & wxApp
Post by: Danishx83 on May 06, 2012, 07:46:33 pm
My limited exposure to the world of coding says that such a change to the templets should be easy and improvement.
Title: Re: redefinition of wxFrame & wxApp
Post by: oBFusCATed on May 06, 2012, 09:16:51 pm
the problem is that when I named my project as "wx", it created the class wxFrame for my application and was trying to extend the project wxFrame with base class wxFrame. I think a simple solution to it would be to append a "_" or some char between the project name and object type (Frame, Dialog etc) so that no project name could ever replicate the original base class identifiers.
Doesn't sound like a good solution...