使用不完整类型'struct QDeclarativeProperty'无效

时间:2013-02-12 10:23:37

标签: qt symbian

此代码:

QGraphicsObject *object=rootObject();
object->setProperty("width", 100);
QDeclarativeProperty(object, "width").write(100);

给出以下错误:

Invalid use of incomplete type 'struct QDeclarativeProperty'

1 个答案:

答案 0 :(得分:3)

添加

#include <QDeclarativeProperty>

到源代码的顶部。似乎在代码的某处,已经有QDeclarativeProperty的前向声明,因此编译器知道它是一个类/结构,但缺少实际的类定义。

以下源代码正确运行在编译器中:

#include <QCoreApplication>
#include <QVariant>
#include <QDeclarativeProperty>

int main(int argc, char ** argv) {
    QCoreApplication a(argc, argv);

    QObject *object = 0; // rootObject();
    object->setProperty("width", 100);
    QDeclarativeProperty(object, "width").write(100);   
}

替换#include <QDeclarativeProperty>
class QDeclarativeProperty;

您收到以下编译时错误:

main.cpp: In function 'int main(int, char**)':
main.cpp:11:38: error: invalid use of incomplete type 'struct QDeclarativeProperty'
main.cpp:4:7: error: forward declaration of 'struct QDeclarativeProperty'