Search code examples
qtqmlqobjectqqmlcomponent

Names of QML nested items


I'm trying to parse QML file using QQmlComponent:

  QQmlComponent component(&engine,
          QUrl::fromLocalFile("src/WorkModels/MyModel.qml"));
  QObject *object = component.create();
  qDebug() << toJson(object);
  foreach(auto action,  object->findChildren<QQuickItem*>()) {
    qDebug() << toJson(action);
  }

But I also need the name of each child Item as it mentioned in QML source. For root it is "MyModel" but how to get it for children? objectName is empty for them.


Solution

  • metaObject()->className() for found children gives me what I needed.