【问题标题】:Names of QML nested itemsQML 嵌套项的名称
【发布时间】:2018-06-07 10:34:38
【问题描述】:

我正在尝试使用 QQmlComponent 解析 QML 文件:

  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);
  }

但我还需要 QML 源代码中提到的每个子项的名称。对于 root,它是“MyModel”,但如何为孩子们获取它? objectName 对他们来说是空的。

【问题讨论】:

    标签: qt qml qobject qqmlcomponent


    【解决方案1】:

    metaObject()-&gt;className() for found children 给了我我需要的东西。

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多