• 6300阅读
  • 2回复

[提问]Q_PROPERTY宏无法使用,报出'xxx' was not declared in this scope [复制链接]

上一主题 下一主题
离线小怪兽
 
只看楼主 倒序阅读 楼主  发表于: 2011-04-06
我使用的是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这行代码编译就没有问题。请问有人知道错误原因吗?
离线小怪兽
只看该作者 1楼 发表于: 2011-04-06
悲剧。。。提交的时候报了错,原来提交了这么多。。。

拜托管理员帮忙删除一下多余的吧,谢谢了。。。
离线dbzhang800

只看该作者 2楼 发表于: 2011-04-06
weight, setWeight 这两个函数你还没定义
快速回复
限100 字节
 
上一个 下一个