I am learning C++ GUI program and trying to develop using wxWidgets. From one of the articles of code project I built up the Hello World GUI project. When I build and run the project I get the error:
\wxHelloWorldMain.h|49|error: 'wxStaticText' does not name a type
Need help to resolve the same.
What I have tried:
I tried to understand the message but could not understand. I am new in this field.
Thank you for the quick reply. I give below the details of the code and error messages:
Following is the wxHelloWorldMain.cpp:
#include "wxHelloWorldMain.h"
#include <wx msgdlg.h="">
#include <wx intl.h="">
#include <wx string.h="">
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
const long wxHelloWorldFrame::ID_STATICTEXT1 = wxNewId();
const long wxHelloWorldFrame::ID_BUTTON1 = wxNewId();
const long wxHelloWorldFrame::ID_PANEL1 = wxNewId();
const long wxHelloWorldFrame::ID_MENUITEM1 = wxNewId();
const long wxHelloWorldFrame::idMenuAbout = wxNewId();
const long wxHelloWorldFrame::ID_STATUSBAR1 = wxNewId();
BEGIN_EVENT_TABLE(wxHelloWorldFrame,wxFrame)
END_EVENT_TABLE()
wxHelloWorldFrame::wxHelloWorldFrame(wxWindow* parent,wxWindowID id)
{
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer2;
wxMenu* Menu1;
wxMenu* Menu2;
wxMenuBar* MenuBar1;
wxMenuItem* MenuItem1;
wxMenuItem* MenuItem2;
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Hello World"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
BoxSizer2->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button1 = new wxStaticText(Panel1, ID_BUTTON1, _("Quit"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer2->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(BoxSizer2);
BoxSizer2->Fit(Panel1);
BoxSizer2->SetSizeHints(Panel1);
BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxHelloWorldFrame::OnButton1Click);
Connec
The message that you received is not complete. I have edited the message but it seems that the full message consisting of wxHelloWorldMain.cpp, wxHelloWorldMain.h, wxHelloWorldApp.cpp, wxHelloWorldApp.h and error message.
I give below wxHelloWorldMain.h
#ifndef WXHELLOWORLDMAIN_H
#define WXHELLOWORLDMAIN_H
#include <wx button.h="">
#include <wx frame.h="">
#include <wx menu.h="">
#include <wx panel.h="">
#include <wx sizer.h="">
#include <wx statbox.h="">
#include <wx statusbr.h="">
class wxHelloWorldFrame: public wxFrame
{
public:
wxHelloWorldFrame(wxWindow* parent,wxWindowID id = -1);
virtual ~wxHelloWorldFrame();
private:
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnButton1Click(wxCommandEvent& event);
static const long ID_STATICTEXT1;
static const long ID_BUTTON1;
static const long ID_PANEL1;
static const long ID_MENUITEM1;
static const long idMenuAbout;
static const long ID_STATUSBAR1;
wxPanel* Panel1;
Line49 wxStaticText* Button1;
Line50 wxStaticText* StaticText1;
wxStatusBar* StatusBar1;
DECLARE_EVENT_TABLE()
};
#endif // WXHELLOWORLDMAIN_H
Error Message
||=== Build: Debug in wxHelloWorld (compiler: GNU GCC Compiler) ===|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.h|49|error: 'wxStaticText' does not name a type|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.h|50|error: 'wxStaticText' does not name a type|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp||In constructor 'wxHelloWorldFrame::wxHelloWorldFrame(wxWindow*, wxWindowID)':|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|73|error: 'StaticText1' was not declared in this scope|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|73|error: expected type-specifier before 'wxStaticText'|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|75|error: 'Button1' was not declared in this scope|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|75|error: expected type-specifier before 'wxStaticText'|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|127|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated [-Wdeprecated-declarations]|
C:\wxWidgets-2.8.12\include\wx\window.h|1453|note: declared here|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|127|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated [-Wdeprecated-declarations]|
C:\wxWidgets-2.8.12\include\wx\window.h|1453|note: declared here|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.cpp|127|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated [-Wdeprecated-declarations]|
C:\wxWidgets-2.8.12\include\wx\window.h|1453|note: declared here|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.h|49|error: 'wxStaticText' does not name a type|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldMain.h|50|error: 'wxStaticText' does not name a type|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldApp.cpp|33|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated [-Wdeprecated-declarations]|
C:\wxWidgets-2.8.12\include\wx\window.h|1453|note: declared here|
F:\CPrograms\wxCB_GUI_Projects\wxHelloWorld\wxHelloWorldApp.cpp|33|warning: 'virtual void wxWindowBase::SetInitialBestSize(const wxSize&)' is deprecated [-Wdeprecated-declarations]|
C:\wxWidgets-2.8.12\include\wx\window.h|1453|note: declared here|
||=== Build
Line 49 and 50 are
wxStaticText* Button1;
wxStaticText* Static