wxWidgets - Event table vs Connect()?

梦想的初衷 提交于 2019-12-23 07:48:07

问题


I have just started learning wxWidgets, version 3.0, with C++. I have noted, that event handling in wxWidgets is done by Event tables. But one tutorial also mentioned Connect() - actually it just said : " this tutorial will be using event tables, not Connect() " .

I would like to know, what is the philosophy behind Event tables and behind Connect() ? What is the difference, when is one more suitable than the other... Thank you.


回答1:


First, don't use Connect() which was superseded by Bind() which is better in every way.

Second, both static (using event tables) and dynamic (using Bind()) methods of handling events work and you can use whichever you prefer. Personally, I recommend using Bind() because

  1. It is much more flexible: can be used to connect the event on one object to any other object or even a free function or, in C++11, a lambda.
  2. It is safer and catches most common errors such as using wrong event handler signature at compile time.
  3. It is "dynamic", i.e. you can connect and disconnect the handler at any time.

The main advantages of the event tables are that

  1. They are slightly shorter, especially in pre 3.0 versions.
  2. They are much more common in documentation, examples, tutorials, ... just because they had a 15 year head start on Bind().

However they are clumsier to use because they require subclassing (deriving a new class from) an object in order to handle non-command events in it and they don't detect all errors at compile-time allowing you to write code that compiles fine but crashes at run-time.



来源:https://stackoverflow.com/questions/21654064/wxwidgets-event-table-vs-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!