wxWidgets没有wx主程序 - 如何编码?

时间:2016-11-22 13:34:47

标签: c++ wxwidgets

我正在尝试编写应用程序的另一部分调用的应用程序的wxWidgets组件,因此没有wxWidgets主程序。我在找到正确的呼叫顺序时遇到了一些问题。

据我所知,首先我需要继承wxApp

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

当我想启动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();

但它永远不会调用OnInit()。有谁知道我应该做什么?

这个问题与wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?不同,因为他们想要调用事件循环(所以他们想要wxEntryStart())但我想要事件循环(事实证明,我想要wxEntry())。

1 个答案:

答案 0 :(得分:2)

wxEntryStart()确实不会调用OnInit(),只会调用wxEntry()

因此,您可以使用wxEntry()(也称为OnRun())或手动拨打wxTheApp->CallOnInit()

详情请见此处:wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?