我有以下非常简单的类:
#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/