1

I'm trying to write a wxWidgets component of an app that is called by another part of the app, so that there is no wxWidgets main program. I am having some problems finding the correct sequence of calls.

As I understand it, first I need to subclass wxApp:

class TestApp : public wxApp {
public:
    virtual bool OnInit() override;
};
bool TestApp::OnInit()  {
    cerr << "app init\n"<<flush;
}

Then I need to do something like this when I want to start up wxWidgets:

    TestApp* app = new TestApp();
    cerr << "a\n";
    wxApp::SetInstance(app);
    cerr << "b\n";
    int argCount = 0;
    char* argv[0];
    if(! wxEntryStart(argCount, argv)) {
        cerr << "wx failed to start\n";
        wxExit();
    }
    cerr << "d\n";
    int res = wxGetApp().OnRun();

But it never calls OnInit(). Does anyone know what I should be doing?

This question is different from wxWidgets: How to initialize wxApp without using macros and without entering the main application loop? in that they do not want to call the event loop (so they want wxEntryStart()) but I do want the event loop (so, it turns out, I want wxEntry()).

Community
  • 1
  • 1
Martin Ellison
  • 1,043
  • 1
  • 13
  • 25
  • Possible duplicate of [wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?](http://stackoverflow.com/questions/208373/wxwidgets-how-to-initialize-wxapp-without-using-macros-and-without-entering-the) – EmDroid Nov 22 '16 at 13:48

1 Answers1

3

wxEntryStart() indeed does not call OnInit(), only wxEntry() does.

So you can either use wxEntry() (which also calls OnRun()) or call wxTheApp->CallOnInit() manually.

See here for details: wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?

Community
  • 1
  • 1
EmDroid
  • 5,918
  • 18
  • 18