我使用的是Qt SDK for Windows*,QT版本是4.7.0,MinGW编译
查看assistant介绍Q_PROPERTY使用方法后编写测试类:
#ifndef BASEOBJECT_H
#define BASEOBJECT_H
#include <QObject>
public BaseObject : public QObject
{
Q_OBJECT
Q_PROPERTY(double weight READ weight WRITE setWeight)
public:
explicit BaseObject(QObject *parent = 0);
~BaseObject();
};
#endif
编译的时候,报出错误:
debug\moc_baseobject.cpp: In member function 'virtual int WorldView::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_baseobject.cpp:75: error: 'weight' was not declared in this scope
debug\moc_baseobject.cpp:78: error: 'setWeight' was not declared in this scope
mingw32-make[1]: Leaving directory `E:/CodeSource/QWorldEngine-build-desktop'
mingw32-make: Leaving directory `E:/CodeSource/QWorldEngine-build-desktop'
mingw32-make[1]: *** [debug/moc_baseobject.o] Error 1
mingw32-make: *** [debug] Error 2
是环境设置问题还是其它?如果我删除Q_PROPERTY这行代码编译就没有问题。请问有人知道错误原因吗?