Results 1 to 3 of 3

Thread: Interoperability of C Callback function and Qt

  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Interoperability of C Callback function and Qt

    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?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Interoperability of C Callback function and Qt

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interoperability of C Callback function and Qt

    Or make the main window a singleton.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Non-Gui thread Callback API and Qt - how
    By The Storm in forum Qt Programming
    Replies: 9
    Last Post: 3rd November 2008, 19:24
  2. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 12:53
  3. Callback in QT
    By gajendersingh in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 10:52
  4. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  5. how to define the callback function in QThread?
    By cxl2253 in forum Qt Programming
    Replies: 6
    Last Post: 30th March 2007, 10:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.