CALLBACK macro (QT)
CALLBACK macro (QT)
我有一个带有这样签名的函数
int iV_SetSampleCallback(pDLLSetSample pSampleCallbackFunction)
pDLLSetSample
在哪里
typedef int (CALLBACK * pDLLSetSample) (struct SampleStruct rawDataSample);
我想将我的成员函数作为回调传递
int sampleCallbackFunction(struct SampleStruct sample);
当我称它为像
iV_SetSampleCallback(&MainWindow::sampleCallbackFunction);
我收到错误
error: C2664: 'int iV_SetSampleCallback(pDLLSetSample)': cannot convert argument 1 from 'int (__thiscall MainWindow::* )(SampleStruct)' to 'pDLLSetSample'
我不明白为什么会发生这种情况。什么是CALLBACK
宏?__thiscall
从何而来?我应该如何正确地将回调传递给此函数?
发生错误是因为您尝试传递指向非静态类成员函数的指针sampleCallbackFunction
而不是指向常规函数的指针。请注意,非静态类成员函数具有显式this
参数。CALLBACK
宏通常用于 Windows,通常代表stdcall
调用约定。
要修复此错误,您需要
- 将成员回调函数声明为静态 将 CALLBACK
- 宏附加到成员函数,以便它具有预期的调用约定(或任何 CALLBACK 扩展的内容)
static int CALLBACK sampleCallbackFunction(struct SampleStruct sample);
相关文章:
- Qt VTK交互风格的信号到小部件
- QT在错误的班级中寻找空位
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 如何在Qt C++中更改光标
- 如何在MS Visual Studio 2019中运行QT UI
- QT通过C++添加映射QML项目
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用Qt C++计算类似Git的SHA1哈希
- Qt focusObjectChanged example?
- 如何在cpp文件之间切换窗口?在Qt中
- Qt和C++:将QLineEdit添加到QTabWidget中
- 从数据库实时显示QT c++中的数据
- Qt Quick-如何仅从c++代码与qml属性交互
- 无法使用Qt Creator在Windows中构建yaml-cpp
- CALLBACK macro (QT)
- QT Macro q_slots'''类访问限制之后
- Qt with Visual Studio macro issue