C++ 没有wx主程序的wxWidgets——如何编码?

C++ 没有wx主程序的wxWidgets——如何编码?,c++,wxwidgets,C++,Wxwidgets,我正在尝试编写一个应用程序的wxWidgets组件,该组件由应用程序的另一部分调用,因此没有wxWidgets主程序。我在查找正确的调用顺序时遇到一些问题 据我所知,首先我需要子类化wxApp: class TestApp : public wxApp { public: virtual bool OnInit() override; }; bool TestApp::OnInit() { cerr << "app init\n"<<flush; }

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

据我所知,首先我需要子类化
wxApp

class TestApp : public wxApp {
public:
    virtual bool OnInit() override;
};
bool TestApp::OnInit()  {
    cerr << "app init\n"<<flush;
}
类TestApp:public wxApp{
公众:
虚拟bool OnInit()覆盖;
};
bool TestApp::OnInit(){
cerr
wxEntryStart()
确实不调用
OnInit()
,只有
wxEntry()
调用

因此,您可以使用
wxEntry()
(它也调用
OnRun()
)或手动调用
wxTheApp->CallOnInit()


有关详细信息,请参见此处:

可能重复的Yes,`wxEntry`调用
OnInit()
。谢谢。
    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();