PDA

View Full Version : Interoperability of C Callback function and Qt



Vogel Ubrhar
17th March 2010, 13:08
Hi I am trying to capture a joystic button press events from low level driver code which calls into a C function that I imported into the Qt project along with my main app. The callback is defined as this:

joystick.c file:

#ifdef __cplusplus
extern "C"
{
#endif

int EventHandler_InputDeviceCallback( Handle t, char* pCommandData, void *pContext )
{
//identify event from joystic and trigger an event
}

: :: ::

#ifdef __cplusplus
}
#endif


All I want to do is call a member in MainWindow class which is also part of the project. How do I do it easily? I tried to pass MainWindow::this as the context during call back setup, and tried to typecst it witth Reinterpret_Cast and tried o call a method but it crashes.

There doesnt seem to be any connection whatsoever between the two, Can I use a global variable?

squidge
17th March 2010, 13:22
Use a static member function, or pass a pointer to an instance of the class as user data and cast that to the class type.

wysota
17th March 2010, 16:02
Or make the main window a singleton.