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.
// MyCustomClass.h
...
protected:
static void XN_CALLBACK_TYPE OnPointUpdate(const XnVHandPointContext* pContext, void* cxt);
signals:
mySignal(QVector3D v);
...
//=======================
//=======================
// MyCustomClass.cpp
...
void XN_CALLBACK_TYPE MyCustomClass::OnPointUpdate(const XnVHandPointContext* pContext, void* cxt)
{
QVector3D v;
v.setX(pContext->ptPosition.X);
v.setY(pContext->ptPosition.Y);
v.setZ(pContext->ptPosition.Z);
// this is where the problems start...
emit static_cast<MyCustomClass*>(cxt)->mySignal(v);
}
...
// MyCustomClass.h
...
protected:
static void XN_CALLBACK_TYPE OnPointUpdate(const XnVHandPointContext* pContext, void* cxt);
signals:
mySignal(QVector3D v);
...
//=======================
//=======================
// MyCustomClass.cpp
...
void XN_CALLBACK_TYPE MyCustomClass::OnPointUpdate(const XnVHandPointContext* pContext, void* cxt)
{
QVector3D v;
v.setX(pContext->ptPosition.X);
v.setY(pContext->ptPosition.Y);
v.setZ(pContext->ptPosition.Z);
// this is where the problems start...
emit static_cast<MyCustomClass*>(cxt)->mySignal(v);
}
...
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
Bookmarks