无法直接从我的代码调用事件处理程序。 2 年前我在这里发现了同样的问题。 original question
但是线
me_InsertCommentText(wxCommandEvent());
未编译(mingw32-gcc 4.8、win7、codeblocks、wxFormBuilder)
error: no matching function for call to 'mjpgen_wdDialog::me_InsertCommentText(wxCommandEvent)' note: candidate is: note: void mjpgen_wdDialog::me_InsertCommentText(wxCommandEvent&)
对我来说,这似乎是由引用参数调用引起的。 我怎样才能让它发挥作用?
最佳答案
关于使用命名临时变量的答案在技术上是正确的,但重要的是你真的不应该首先这样做。处理程序只应该从 wxWidgets 调用,而不是直接调用一些 OnFoo(wxFooEvent&)
你应该重构你的代码,从 调用一些新的
,然后在需要时从其余代码中调用 DoFoo()
>OnFoo()DoFoo()
。
这在使用 C++11 时变得更加简单,因为在这种情况下您甚至根本不需要 OnFoo()
并且可以只写
whatever->Bind(wxEVT_FOO, [=](wxCommandEvent&) { DoFoo(); });
避免额外的功能。
关于c++ - 直接调用事件处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995321/