Unsolved To access QList<QPointF> property value in cpp side using qmetaProperty
-
I have defined a class using QObject and defined a property in it using Q_PROPERTY of type QList<QPointF>. I can access this property in QML side. But by using the object pointer, if i try to read the property value using qmetaproperty, i gets the value as QVariant(QList<QPointF>, ) like an empty list rather than actual value list.
Ex:
cpp side:class ExampleObj
{
QObject
Q_PROPERTY(QList<QPointF> prop READ prop WRITE setProp NOTIFY propChanged)
...
QList<QPointF> prop() {
QPointF p (1,2);
QList<QPointF> pointL;
pointL << p << p << p;
return point L;
}...
...};
QML side:
ExampleObj{
// I can access the 'prop' values, and modify them in QML side
}Cpp side:
QQuickItem *obj = qobject_cast<QQuickItem *>(qmlExampleObj.value<QObject *>());
const QMetaObject *meta_object = obj->metaObject();
const QMetaProperty meta_property = meta_object->property("prop");
qDebug() << meta_property.read(obj);
// output: QVariant(QList<QPointF>, )
//But expecting output as QVariant(QList<QPointF>, (QPointF(1,2), QPointF(1,2), QPointF(1,2)))Could you please guide me if i missed anything here ?. Thanks
-
Rather than using QList<QPointF>, if I use QVariantList as a data type when defining the property using Q_PROPERTY, then this solves the problem. But is this a correct way or are there any better way?
-
Are you sure it's emply and not just not displayed in qDebug?
what about
qDebug() << meta_property.read(obj).value<QList<QPointF>>();
?