event handler

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
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 23, 2007 3:41 pm
Location: London

event handler

Post by Qasim » Tue Mar 18, 2008 9:48 am

Hi, I am trying to attach my fun with a menu. I am doing some thing like this in xp, Visual Studio 2005

//this is global function(not member of any class)

Code: Select all

void myFunc()
int x = 0;

then in

Code: Select all

void MyFrame::createcontrols()
wxMenu* menu = new wxMenu;
menu->Append(1100, "MyMenu");
menu->Connect(1100, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(myFunc), NULL, NULL);
having error:

Code: Select all

error C2440: 'static_cast' : cannot convert from 'void (__cdecl *)(void)' to 'wxCommandEventFunction'
Any help will be appreciated.
Who doubts nothing, Knows nothing

Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands

Post by Jorg » Tue Mar 18, 2008 10:09 am

You can't connect functions to an event handler. The event sink has to be of the same base class (wxEvtHandler).

Create a normal event handler inside your class, and in there call the gliobal function.

= Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
Jorg's WasteBucket

Post Reply