c++ - Q_DECLARE_METATYPE 抛出缺少类型说明符错误

标签 c++ qt

我有以下非常简单的类:

#ifndef SLAVECALIBRATIONGRAB
#define SLAVECALIBRATIONGRAB

#include <stdint.h>

class SlaveCalibrationGrab{
public:
    SlaveCalibrationGrab() : data(0) {}
    SlaveCalibrationGrab(int data_) : data(data_){}

    SlaveCalibrationGrab(const SlaveCalibrationGrab& other){
        data = other.data;
    }


    ~SlaveCalibrationGrab(){}

private:
   int data;
};

Q_DECLARE_METATYPE(SlaveCalibrationGrab);

#endif

这会引发以下错误:

C4430: missing type specifier - int assumed. Note: C++ does not support default-int

有人知道我做错了什么吗?

最佳答案

我假设你在谈论 Qt 的 Q_DECALRE_METATYPE ?这是在 #include <QMetaType> 中定义的.添加包括。这是文档的链接:Qt5.5 QMetaType

引自文档:

Ideally, this macro should be placed below the declaration of the class or struct. If that is not possible, it can be put in a private header file which has to be included every time that type is used in a QVariant.

Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. Note that if you intend to use the type in queued signal and slot connections or in QObject's property system, you also have to call qRegisterMetaType() since the names are resolved at runtime.

关于c++ - Q_DECLARE_METATYPE 抛出缺少类型说明符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35939581/

相关文章:

c++ - 如何根据第一个或第二个中的较大值对数组对进行排序

c++ - 手动执行 exe 时出现运行时错误

c++ - 用3D+2D图形重绘QGLWidget

c++ - auto c++ 关键字有什么作用?

c++ - 变量在 if 语句中不可访问

c++ - 将单个字符 QString 转换为 Char

c++ - 是否可以判断 C++ 文件何时是主要源文件?

qt - Qt循环播放背景音乐

c++ - Qt QLabel 默认文本

c++ - QTableWidgetItem 文本已更改