سؤال

This code:

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

gives the following error:

Invalid use of incomplete type 'struct QDeclarativeProperty'
هل كانت مفيدة؟

المحلول

Add

#include <QDeclarativeProperty>

to the top of your source code. It seems that somewhere in your code, there is already a forward declaration for QDeclarativeProperty, so the compiler knows that it is a class/struct, but the actual class definition is missing.

The following source code properly runs through the compiler:

#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);   
}

When you replace #include <QDeclarativeProperty> with

class QDeclarativeProperty;

you get the following compile time error:

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'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top