1

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!

2
  • Have you tried dial->metaObject->property(index); in a loop with the propertyCount() method and then the name() method? Commented May 23, 2014 at 19:37
  • That will do it! Thankyou :) Commented May 24, 2014 at 2:02

1 Answer 1

1

You could write it:

for (int i = 0; i < dial->metaObject->propertyCount(); ++i) {
    QMetaProperty metaProperty = dial->metaobject()->property(i);
    qDebug() << metaProperty.name();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.