【问题标题】:wxWidgets without wx main program -- how to code?wxWidgets 没有 wx 主程序——如何编码?
【发布时间】:2017-04-06 05:02:02
【问题描述】:

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

【问题讨论】:

标签: c++ wxwidgets


【解决方案1】:

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

因此您可以使用wxEntry()(也可以调用OnRun())或手动调用wxTheApp-&gt;CallOnInit()

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

【讨论】:

  • 是的,` wxEntry` 调用OnInit()。谢谢。
猜你喜欢
  • 2015-08-08
  • 1970-01-01
  • 2021-06-18
  • 2018-08-03
  • 2016-02-14
  • 2022-09-24
  • 2017-02-21
  • 2011-08-10
  • 1970-01-01
相关资源
最近更新 更多