如何将非静态函数作为回调传递?
我目前正在使用Qt和图形引擎,并且在QGLWidget实例初始化期间,我需要向我的引擎传递一些函数指针.
I'm currently working with Qt and a graphics engine and during the init of the QGLWidget instance I need to pass a few function pointers to my engine.
寻找回调的函数是:
virtual void Buffer::CreateCustom( byte* getsize, byte* makecurrent)
Qt提供了 makeCurrent函数,但是它都不是字节*也不是静态的.
Qt provides a makeCurrent function however it is neither byte* nor static.
我可以这样编写一个小的包装函数:
I could write a tiny wrapper function like so:
void _stdcall MakeCurrent(void)
{
QGLContext::makeCurrent();
}
但是它仅意味着从GLWidget实例中调用.我试图创建一个像这样的类成员包装函数:
But its only meant to be called from within an instance of GLWidget. I tried to create a class member wrapper function like so:
void _stdcall LEWidget::leMakeCurrent(void)
{
makeCurrent();
}
但是您只能在静态成员函数上提供函数指针.如果执行此操作,则会出现以下错误:
But you can only provide function pointers on static member functions. If I do that I get the following error:
错误C2352:'QGLWidget :: makeCurrent':非法调用了非静态成员函数.非静态成员引用必须相对于特定对象.
看到这个问题,我认为这几乎是您想要做的事情:
See this question, I think it is pretty much what you want to do: