Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Enumerate QML properties in Qt C++?
Forum Updated to NodeBB v4.3 + New Features

Enumerate QML properties in Qt C++?

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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
    MWPau
    wrote on last edited by
    #1

    Greetinsg all,

    Im doing the following to render a QML in my Qt embedded app:
    @
    QDeclarativeView *view = new QDeclarativeView(this);
    view->setSource(QUrl::fromLocalFile("dial.qml"));
    view->show();
    QObject *dial = view->rootObject();
    @

    Is there a way i can enumerate all the property values defined in the root item?

    For example, if i have the QML:
    @
    import QtQuick 1.0
    Item {
    id: root
    property real dial_value : 0
    property real dial_length: 0
    property real background_opacity: 1
    etc, etc
    }
    @

    Is there a Qt method that will end up with me having a list of these strings:
    @
    dial_value
    dial_length
    background_opacity
    @

    Ive tried, the following, but it the list is empty:
    @
    QList<QByteArray> list = dial->dynamicPropertyNames();
    @

    Thanks in advance!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      The "rootObject()" is not your "root" item!

      Best way (in my opinion) is to add objectName to your root object:
      @
      Item {
      objectName: "myRoot"
      id: root
      ...
      }
      @

      Then, in C++, you can get that object using QObject::findChildren() or findChild():
      @
      QObject *dial = view->finChild<QObject *>("myRoot");
      @

      Then you can iterate over every property that object has using QObject::metaObject().

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MWPau
        wrote on last edited by
        #3

        Oh, nice!

        Thankyou :)

        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