Results 1 to 4 of 4

Thread: How to emit signal from static callback function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to emit signal from static callback function

    Hi,

    Is there a way of emitting a signal from static callback function?
    Below is the example I found online which apparently should be fine.

    Qt Code:
    1. // MyCustomClass.h
    2. ...
    3. protected:
    4. static void XN_CALLBACK_TYPE OnPointUpdate(const XnVHandPointContext* pContext, void* cxt);
    5.  
    6. signals:
    7. mySignal(QVector3D v);
    8. ...
    9.  
    10. //=======================
    11. //=======================
    12.  
    13. // MyCustomClass.cpp
    14. ...
    15. void XN_CALLBACK_TYPE MyCustomClass::OnPointUpdate(const XnVHandPointContext* pContext, void* cxt)
    16. {
    17. QVector3D v;
    18. v.setX(pContext->ptPosition.X);
    19. v.setY(pContext->ptPosition.Y);
    20. v.setZ(pContext->ptPosition.Z);
    21.  
    22. // this is where the problems start...
    23.  
    24. emit static_cast<MyCustomClass*>(cxt)->mySignal(v);
    25.  
    26. }
    27. ...
    To copy to clipboard, switch view to plain text mode 

    When I tried to debug my program to see where it fails, this is what I got:

    "Unhandled exception at 0x60893f3a (QtCored4.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000004."

    ... and that happened in QScopedPointer.h at line 135.

    Currently I'm using a global variable to access my 'QVector3D v'.
    Is there a better way of overcoming this problem?

    Thank you.

    Krzysztof
    Last edited by blizniak83; 12th April 2012 at 20:56. Reason: updated contents

Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 21:36
  2. Can you send a signal from a static callback function?
    By Eos Pengwern in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2010, 13:47
  3. emit a signal from inside a callback routine
    By franco.amato in forum Qt Programming
    Replies: 20
    Last Post: 21st January 2010, 18:05
  4. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 12:53
  5. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47

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
  •  
Qt is a trademark of The Qt Company.