WxWidgets - Event table vs Connect ()?

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

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

+6
source share
1 answer

First, do not use Connect() , which has been replaced by Bind () , which is the best.

Secondly, both static (using event tables) and dynamic (using Bind() ) event handling methods work, and you can use whatever you prefer. Personally, I recommend using Bind() because

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

The main advantages of event tables are:

  • They are slightly shorter, especially in versions prior to 3.0.
  • They are much more common in documentation, examples, textbooks, ... just because they had a 15-year start on Bind() .

However, they are inconvenient to use because they require a subclass (getting a new class) of the object to handle non-command events in it, and they do not detect all errors during compilation, which allows you to write code that compiles normally, but fails during fulfillment.

+13
source

All Articles