gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:36:21 24 4
gpt4 key购买 nike

我正在尝试编写一个由应用程序的另一部分调用的应用程序的 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()).

最佳答案

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

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

详情请看这里:wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?

关于c++ - 没有wx主程序的wxWidgets——如何编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40743238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com