I'm dealing with sample code from a camera SDK, and I have issues getting the frame data "outside" the CSampleCaptureEventHandler class.
class DahengCamera : public QObject
{
Q_OBJECT
class CSampleCaptureEventHandler : public ICaptureEventHandler
{
void DoOnImageCaptured(CImageDataPointer& objImageDataPointer, void* pUserParam)
{
[grab some data ...]
CopyToImage(objImageDataPointer); // illegal call of non-static member function
}
};
public:
DahengCamera();
~DahengCamera();
private:
void CopyToImage(CImageDataPointer pInBuffer); // I want to have my frame datas here
QImage m_data; //and here
};
I'm using a callback register call to make the camera "DoOnImageCaptured" event called once a frame is grabbed by the system. But I'm stuck getting the data outside this method. CopyToImage() is supposed to get a reference to QImage or to write into m_data, but I have "illegal call of non-static member function" errors. Tried to make CopyToImage() static, but it just move the problem...
How can I solve this ?
Thanks !
CodePudding user response:
CopyToImage
is a private non-static function in the class DahengCamera
.
The fact that CSampleCaptureEventHandler
is a nested class inside DahengCamera
allows it to access DahengCamera
's private members and functions (as if it were decleared a friend class), but this does not provide CSampleCaptureEventHandler
with a pointers to any DahengCamera
objects.
You need to provide the actual instance of the CSampleCaptureEventHandler
object on which DoOnImageCaptured
is called with a pointer/refence to the DahengCamera
object on which CopyToImage
should be called. You might consider providing this pointer/reference to the DoOnImageCaptured
object to CSampleCaptureEventHandler
's constuctor (i.e. dependency injection).
(And - for your own sake - do not try to "fix" this by turning CopyToImage
or m_data
into static - this would create only a horrible mess)