How to systematically convert an event table into 'Connect' ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
HansLjy
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri May 21, 2021 6:44 am

How to systematically convert an event table into 'Connect' ?

Post by HansLjy »

I try to use the code from https://wiki.wxwidgets.org/An_image_panel but this one uses an event table while I would like to change them into 'Connect'.

The reason I don't like event tables is that I found that if I declare the event table in the header file (I suppose this is necessary?) and include it in multiple files, then the same implementation of event table will get compiled multiple times and this results in a compile error which I run into from time to time.

(BTW, am I right about event table? Or is there another way to use it? I'm new to wxWidgets ...)

As a result I would like to change the event tables into 'Connect' and I wonder if there is a systematic way? For example, if I want to translate the code below:

Code: Select all

BEGIN_EVENT_TABLE(wxImagePanel, wxPanel)
EVT_PAINT(wxImagePanel::paintEvent)
END_EVENT_TABLE()
What would the result be? I have tried the following code:

Code: Select all

Connect(wxEVT_PAINT, wxPaintEventHandler(paintEvent));
It seems workable on my computer. Am I right? How can I get the ID of the event? And how can I know the handler type is wxPaintEventHandler (I just guess it)?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to systematically convert an event table into 'Connect' ?

Post by doublemax »

The reason I don't like event tables is that I found that if I declare the event table in the header file (I suppose this is necessary?)
No, they always go into the .cpp file.

If you still want to avoid event tables, use the more modern Bind(), Connect() only exists for backward compatibility.

Code: Select all

Bind(wxEVT_PAINT, &wxImagePanel::paintEvent, this);
Use the source, Luke!
Post Reply