Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. To access QList<QPointF> property value in cpp side using qmetaProperty
Forum Update on Monday, May 27th 2025

To access QList<QPointF> property value in cpp side using qmetaProperty

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 464 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MKCV
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MKCV
      wrote on last edited by MKCV
      #2

      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?

      1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        Are you sure it's emply and not just not displayed in qDebug?

        what about qDebug() << meta_property.read(obj).value<QList<QPointF>>();?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved