Code::Blocks Forums
Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: mrpringle on January 06, 2007, 12:00:24 pm
-
Hi,
I"m just trying to get the hang of wxWiidgets. There's a few things I don't understand, and I've had trouble compiling a basic application from scratch.
I'm using wxWidgets 2.8.0. I've got a fair understanding of command-line c++ programming, but never dealt with GUI's before.
I'm getting an error when compiling my project which says:
Basic.cpp:: undefined reference to `vtable for BasicFrame'
Basic.cpp:: undefined reference to `vtable for BasicFrame'
:: === Build finished: 2 errors, 0 warnings ===
Here is Basic.h
#ifndef BASIC_H
#define BASIC_H
class Basic: public wxApp
{
public:
virtual bool OnInit();
};
class BasicFrame: public wxFrame
{
public:
BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
~BasicFrame();
};
#endif
___________________________________________________________________
and here is Basic.cpp
#include "basic.h"
#include <wx/wx.h>
IMPLEMENT_APP(Basic)
bool Basic::OnInit()
{
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
frame->Show();
SetTopWindow(frame);
return true;
}
BasicFrame::BasicFrame (const wxString & title, int xpos, int ypos, int width, int height)
: wxFrame(NULL, -1, title, wxPoint (xpos,ypos), wxSize (width, height))
{}
____________________________________________________________________________
For the moment I'm just trying to get a wxFrame showing, and then I'll mess around with event handling and controls, etc.
Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?
I appreciate your time.
-
I would suggest you to build up a very simple frame program by the wizard which included in C::B. Then check each line of the generated source.
I test the wizard in svn build rev 3461 and works fine for me.
-
I got the wizard working, but I don't really understand all the code it generates, so I followed a tutorial off the internet.
Wizards are good, but I would prefer to learn the stuff line by line before I use the wizard.
-
never mind. I worked out what was wrong.
-
I would suggest you to study a book "Cross-Platform GUI Programming with wxWidgets" http://www.wxwidgets.org/docs/book/ (http://www.wxwidgets.org/docs/book/) However, could somebody tell me why there is only one book for wxWidgets? Did I miss something?
-
Here is Basic.h
#ifndef BASIC_H
#define BASIC_H
#include <wx/wx.h> // <-- Missing Header
class Basic: public wxApp
{
public:
virtual bool OnInit();
};
class BasicFrame: public wxFrame
{
public:
BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
~BasicFrame();
};
#endif
Add the missing header, highlighted in red colour, in the Basic.h file.
Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?
That basically converts the char * to wxChar * which is used to construct wxString for title parameter used in frame class' constructor. But this is an advanced call. wxWidgets manual defines it in the following way.
_
const wxChar * _(const char *s)
This macro expands into a call to wxGetTranslation function, so it marks the message for the extraction by xgettext just as wxTRANSLATE does, but also returns the translation of the string for the current locale during execution.
Don't confuse this macro with _T()!
Hope this helps. :)
P.S. - This is a Code::Blocks development related forum. So from next time please post such requests in other section.
-
Here is Basic.h
#ifndef BASIC_H
#define BASIC_H
#include <wx/wx.h> // <-- Missing Header
class Basic: public wxApp
{
public:
virtual bool OnInit();
};
class BasicFrame: public wxFrame
{
public:
BasicFrame(const wxString & title, int xpos, int ypos, int width, int height);
~BasicFrame();
};
#endif
Add the missing header, highlighted in red colour, in the Basic.h file.
Another thing which I'm unsure about is the use of the _ symbol on this line:
BasicFrame *frame = new BasicFrame(_("Sample"), 50,50,450,300);
What does the _ in _("Sample") do?
That basically converts the char * to wxChar * which is used to construct wxString for title parameter used in frame class' constructor. But this is an advanced call. wxWidgets manual defines it in the following way.
_
const wxChar * _(const char *s)
This macro expands into a call to wxGetTranslation function, so it marks the message for the extraction by xgettext just as wxTRANSLATE does, but also returns the translation of the string for the current locale during execution.
Don't confuse this macro with _T()!
Hope this helps. :)
P.S. - This is a Code::Blocks development related forum. So from next time please post such requests in other section.
Thanks.