Qt c++嵌套类/解决非静态成员函数非法调用
Qt c++ nested classes / solve illegal call of non-static member function
我正在处理相机 SDK 中的示例代码,在获取 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
};
我正在使用回调寄存器调用来使系统捕获帧后调用相机“DoOnImageCaptured”事件。但我一直无法在这种方法之外获取数据。 CopyToImage() 应该获得对 QImage 的引用或写入 m_data,但我有“非法调用非静态成员函数”错误。试图使 CopyToImage() 静态,但它只是移动了问题...
我该如何解决这个问题?
谢谢!
CopyToImage
是 class DahengCamera
.
中的私有 non-static 函数
CSampleCaptureEventHandler
是 DahengCamera
中嵌套的 class 的事实允许它访问 DahengCamera
的私有成员和函数(就好像它是一个朋友 class ), 但这不向 CSampleCaptureEventHandler
提供指向任何 DahengCamera
对象的指针。
您需要提供 CSampleCaptureEventHandler
对象的实际实例,其中 DoOnImageCaptured
被调用 pointer/refence 到 DahengCamera
对象 CopyToImage
应该被调用。您可能会考虑将此 pointer/reference 提供给 DoOnImageCaptured
对象到 CSampleCaptureEventHandler
的构造函数(即依赖注入)。
(并且 - 为了您自己的利益 - 不要 尝试通过将 CopyToImage
或 m_data
变成静态来“修复”这个问题 - 这会造成只有一团糟)
我正在处理相机 SDK 中的示例代码,在获取 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
};
我正在使用回调寄存器调用来使系统捕获帧后调用相机“DoOnImageCaptured”事件。但我一直无法在这种方法之外获取数据。 CopyToImage() 应该获得对 QImage 的引用或写入 m_data,但我有“非法调用非静态成员函数”错误。试图使 CopyToImage() 静态,但它只是移动了问题...
我该如何解决这个问题?
谢谢!
CopyToImage
是 class DahengCamera
.
中的私有 non-static 函数
CSampleCaptureEventHandler
是 DahengCamera
中嵌套的 class 的事实允许它访问 DahengCamera
的私有成员和函数(就好像它是一个朋友 class ), 但这不向 CSampleCaptureEventHandler
提供指向任何 DahengCamera
对象的指针。
您需要提供 CSampleCaptureEventHandler
对象的实际实例,其中 DoOnImageCaptured
被调用 pointer/refence 到 DahengCamera
对象 CopyToImage
应该被调用。您可能会考虑将此 pointer/reference 提供给 DoOnImageCaptured
对象到 CSampleCaptureEventHandler
的构造函数(即依赖注入)。
(并且 - 为了您自己的利益 - 不要 尝试通过将 CopyToImage
或 m_data
变成静态来“修复”这个问题 - 这会造成只有一团糟)