Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


Log in to reply