Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6848071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:49:22+00:00 2026-05-27T00:49:22+00:00

NOTE: I completely revised the question and turned it into an example project specifically

  • 0

NOTE: I completely revised the question and turned it into an example project specifically for this question, so Nicks answer doesn’t really make sense anymore. wxQuestionMain.h and wxQuestionMain.cpp are mildly modified wxWidget files, auto generated by Code::Blocks.

go

When I click the “Go” button I want the button event in “wxQuestionMain.cpp” to call “somefunction()” which is inside “otherFile.cpp”. That works just fine. But I then want to change the text in the textbox “txtCtrl1” from inside “somefunction()” and that won’t work because “somefunction()” is not part of the wxWidget class, and I don’t want it to be. The wxwidget class is created in “wxQuestionMain.h”.

wxQuestionMain.h -> Just creates the class

#ifndef WXQUESTIONMAIN_H
#define WXQUESTIONMAIN_H
#define BOOST_FILESYSTEM_VERSION 2

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wxQuestionApp.h"


#include <wx/button.h>
#include <wx/statline.h>
class wxQuestionDialog: public wxDialog
{
    public:
    wxQuestionDialog(wxDialog *dlg, const wxString& title);
    ~wxQuestionDialog();

    protected:
    enum
    {
        idBtnGo = 1000
    };
    wxStaticText* m_staticText1;
    wxStaticLine* m_staticline1;
    wxButton* BtnGo;
    wxTextCtrl* textCtrl1;

    private:
    void OnClose(wxCloseEvent& event);
    void OnGo(wxCommandEvent& event);
    DECLARE_EVENT_TABLE()
};

void somefunction();

#endif // WXQUESTIONMAIN_H

wxQuestionMain.cpp -> Lots of yadda yadda and then at the very bottom the function that handles the buttonclick event.

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "wxQuestionMain.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(__WXMAC__)
    wxbuild << _T("-Mac");
#elif defined(__UNIX__)
    wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
    wxbuild << _T("-Unicode build");
#else
    wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}


BEGIN_EVENT_TABLE(wxQuestionDialog, wxDialog)
    EVT_CLOSE(wxQuestionDialog::OnClose)
    EVT_BUTTON(idBtnGo, wxQuestionDialog::OnGo)
END_EVENT_TABLE()

wxQuestionDialog::wxQuestionDialog(wxDialog *dlg, const wxString &title)
    : wxDialog(dlg, -1, title)
{
    this->SetSizeHints(wxDefaultSize, wxDefaultSize);
    wxBoxSizer* bSizer1;
    bSizer1 = new wxBoxSizer(wxHORIZONTAL);
    m_staticText1 = new wxStaticText(this, wxID_ANY, wxT("Welcome To\nwxWidgets"), wxDefaultPosition, wxDefaultSize, 0);
    m_staticText1->SetFont(wxFont(20, 74, 90, 90, false, wxT("Arial")));
    bSizer1->Add(m_staticText1, 0, wxALL|wxEXPAND, 5);
    wxBoxSizer* bSizer2;
    bSizer2 = new wxBoxSizer(wxVERTICAL);

    wxPoint textCtrl1Position(5,5); //Position
    wxSize textCtrl1size(120,25); //Size
    textCtrl1 = new wxTextCtrl(this, wxID_ANY, "hi", wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, "textCtrl1"); //Create textCtrl
    bSizer2->Add(textCtrl1, 0, wxALL|wxEXPAND, 5); //Add to sizer

    m_staticline1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
    bSizer2->Add(m_staticline1, 0, wxALL|wxEXPAND, 5);
    BtnGo = new wxButton(this, idBtnGo, wxT("&Go"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer2->Add(BtnGo, 0, wxALL, 5);
    bSizer1->Add(bSizer2, 1, wxEXPAND, 5);
    this->SetSizer(bSizer1);
    this->Layout();
    bSizer1->Fit(this);
}


wxQuestionDialog::~wxQuestionDialog()
{
}

void wxQuestionDialog::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void wxQuestionDialog::OnGo(wxCommandEvent &event)
{
    somefunction();
}

otherFile.cpp:

#include "wxQuestionMain.h"

void somefunction()
{
    //Try to change the text in textCtrl1
    wxQuestionDialog::textCtrl1->AppendText("Red text\n");
}

Produces:

error: ‘wxTextCtrl* wxQuestionDialog::textCtrl1’ is protected
error: invalid use of non-static data member ‘wxQuestionDialog::textCtrl1’

So I moved ‘wxTextCtrl* textCtrl1;’ in ‘wxQuestionMain.h’ from ‘protected’ to ‘public’

Produces:

error: invalid use of non-static data member ‘wxQuestionDialog::textCtrl1’

The class in wxQuestionMain.h seems to sais ‘class wxQuestionDialog: public wxDialog’

I don’t know what that “public” part means, I’ve never seen a class be created like that before, but I’m going to try to change ‘otherFile.cpp’ so it sais wxDialog instead of wxQuestionDialog.

#include "wxQuestionMain.h"

void somefunction()
{
    //Try to change the text in textCtrl1
    wxDialog::textCtrl1->AppendText("Red text\n");
}

Produces:

error: ‘textCtrl1’ is not a member of ‘wxDialog’

I’m at a loss here.. how can I update the text in “textCtrl1” without adding “somefunction()” to the wxWidget class?

CodeBlocks auto generated 2 other files, not sure if they are important, but here they are.

wxQuestionApp.cpp

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "wxQuestionApp.h"
#include "wxQuestionMain.h"

IMPLEMENT_APP(wxQuestionApp);

bool wxQuestionApp::OnInit()
{

    wxQuestionDialog* dlg = new wxQuestionDialog(0L, _("wxWidgets Application Template"));

    dlg->Show();
    return true;
}

wxQuestionApp.h

#ifndef WXQUESTIONAPP_H
#define WXQUESTIONAPP_H

#include <wx/app.h>

class wxQuestionApp : public wxApp
{
    public:
    virtual bool OnInit();
};

#endif // WXQUESTIONAPP_H
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:49:23+00:00Added an answer on May 27, 2026 at 12:49 am

    addtolistbox2 is a private member method of gfxDialog – even if you did have a properly constructed object, you wouldn’t be able to call that method from outside a gfxDialog instance. At the very least you need to move addtolistbox2 to public: from private:, and then call it on a properly constructed instance (the constructor requires arguments but your code doesn’t provide them):

    gfxDialog testtime(0, "test");
    testtime.addtolistbox2("somestring");
    

    (The only valid constructor requires a parent dialog and a title string:

    class gfxDialog: public wxDialog
    {
        public:
        gfxDialog(wxDialog *dlg, const wxString& title);
    

    if I remember my wxWidgets properly, the parent may be NULL, but of course you still have to provide the argument)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I'm not completely sure if this question really belongs to StackOverflow so feel
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note : The code in this question is part of deSleeper if you want
NOTE: This is a long question. I've explained all the 'basics' at the top
Rewrote the question completely. Please, read it carefully Single note to not confuse you:
Note: This might seem like a Super User question at first, but please read
EDIT : please note: i completely re-explained my question. I have application with two
(Please note: I have one similar question active - but it's completely different as
NOTE: Updated and rewritten This question has been redone and updated. Please pardon outdated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.