Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
/***************************************************************
 * Name:      wxHelloWorldMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Bipin Mehta ()
 * Created:   2019-08-25
 * Copyright: Bipin Mehta ()
 * License:
 **************************************************************/

#include "wxHelloWorldMain.h"
#include <wx msgdlg.h="">

//(*InternalHeaders(wxHelloWorldFrame)
#include <wx intl.h="">
#include <wx string.h="">
//*)

//helper functions
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;
}

//(*IdInit(wxHelloWorldFrame)
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)
    //(*EventTable(wxHelloWorldFrame)
    //*)
END_EVENT_TABLE()

wxHelloWorldFrame::wxHelloWorldFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(wxHelloWorldFrame)
    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
C++
#ifndef WXHELLOWORLDMAIN_H
#define WXHELLOWORLDMAIN_H

//(*Headers(wxHelloWorldFrame)
#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:

        //(*Handlers(wxHelloWorldFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnButton1Click(wxCommandEvent& event);
        //*)

        //(*Identifiers(wxHelloWorldFrame)
        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;
        //*)

        //(*Declarations(wxHelloWorldFrame)
        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
Posted
Updated 4-Mar-21 20:11pm
v3

You need to show your code and the exact message, and indicate which line causes the error. But first go to wxWidgets: wxStaticText Class Reference[^] and see if that explains what you are doing wrong.
 
Share this answer
 
Comments
Bipin5 26-Aug-19 15:14pm    
Details moved to question.
Richard MacCutchan 26-Aug-19 15:25pm    
The error message referred above is on line 49 of wxHelloWorldMain.h, so that is what we need to see. And when you post it please identify line 49, do not leave us to count.
Bipin5 26-Aug-19 15:37pm    
Details moved to question.
Richard MacCutchan 27-Aug-19 2:50am    
You are missing the #include <wx/stattext.h> statement, as referenced in the link I gave you above.
Bipin5 27-Aug-19 7:10am    
Thank you for the suggestion. I could not understand in which file should I add "#include<wx stattext.h="">. I added in wxHelloWorpdMain.cpp and run the program. I got more errors. Then I add in wxHelloWorldMain.h. Here also I got more errors.

I decided to redo the whole project from scratch once again as per details given in the codeproject article. I got the result ok. The only point I was not happy was with the look of the wxpanel. But this is minor.

Thank you for all the support.
quick googling gives you
#include <wx/stattext.h>
 
Share this answer
 
ror 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
 
Share this answer
 
Comments
CHill60 5-Mar-21 4:16am    
I am assuming that you have a problem in which case you should use the red "Ask a Question" link and not post questions as a solution to another member's post.
When you post your question include more of your code. wxStaticText has not been defined as a type but we can't tell what the full problem is without seeing the actual code!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900