Event fails to call event function Topic is solved

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
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Event fails to call event function

Post by beneficii » Thu Feb 22, 2018 9:27 pm

I'm using wxWidgets 3.0.3 on Windows 8.1, with my IDE being Visual Studio 2017 Community.

I inherited from wxScrolled<wxWindow> to create EditWindow, which has the event myEVT_TILEHOVER declared and defined, along with EditWindowEvent which inherits from wxEvent, EditWindowEventFunction which is a typedef, EditWindowEventHandler which is a #define that uses wxEVENT_HANDLER_CAST, and EVT_TILEEDIT a #define that is used on the relevant frame's event table.

So it's on a frame, MyFrame, which inherits from wxFrame. The class function MyFrame::OnTileHover() is the one that is supposed to handle the event. The actual sender of the event is a PaletteWindow, which inherits from EditWindow.

On debugging it, I find that the internal function in EditWindow which handles the EVT_MOTION DOES get called properly, but upon calling wxPostEvent(), the MyFrame::OnTileHover() handler never gets called.

What am I doing wrong here? The project is attached. The event is supposed to be activated when you move the mouse over the PaletteWindow in the lower left part of the screen.
Attachments
sfcTileMapEditor.zip
(14.63 KiB) Downloaded 18 times

User avatar
doublemax
Moderator
Moderator
Posts: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event fails to call event function

Post by doublemax » Thu Feb 22, 2018 9:57 pm

I only took a quick glance at the code, my first guess would be: Derive EditWindowEvent from wxCommandEvent instead of wxEvent, because only those propagate upwards in the window hierarchy.
Use the source, Luke!

beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Re: Event fails to call event function

Post by beneficii » Thu Feb 22, 2018 11:10 pm

OK, got it, thanks!

BTW, if I use wxQueueEvent() instead of wxPostEvent(), it crashes. Why is this?

User avatar
doublemax
Moderator
Moderator
Posts: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event fails to call event function

Post by doublemax » Fri Feb 23, 2018 12:02 am

BTW, if I use wxQueueEvent() instead of wxPostEvent(), it crashes. Why is this?
Because wxQueueEvent expects a pointer to an event that was created on the heap and deletes it afterwards.

(As stated in the documentation...)
http://docs.wxwidgets.org/trunk/group__ ... d2c408bce1
Use the source, Luke!

Post Reply