我正在尝试编写应用程序的另一部分调用的应用程序的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()
)。
答案 0 :(得分:2)
wxEntryStart()
确实不会调用OnInit()
,只会调用wxEntry()
。
因此,您可以使用wxEntry()
(也称为OnRun()
)或手动拨打wxTheApp->CallOnInit()
。