【问题标题】:QML property hint by dot notaton点表示法的 QML 属性提示
【发布时间】:2018-07-13 09:54:42
【问题描述】:
class A{
    QList<B *>child;
    Q_INVOKABLE B * getChild(int idx) {return child.at(idx);}
}

class B{
    int age;
}

in QML:
Item{
  A{
    id: a;
  }
  Componet.onCompleted:{
    console.log: a.getChild(0).age;
  }
}

我有两个班级 A 和 B。 我已经注册了 A 类和 B 类 int main.cpp。 我可以得到正确的值,但我希望在 a.getChild(0) 之后,如果我不知道 B 类有什么属性,我能够通过点表示法获得提醒。

【问题讨论】:

    标签: properties qml qlist


    【解决方案1】:

    是的,您可以在 Qml 中迭代对象 B 的所有属性。但是你会得到所有的属性,包括信号和槽。

    在 QML 中:

    Item{
      A {
        id: a;
      }
      Componet.onCompleted: {
        var bItem = a.getChild(0)
        for (var p in bItem )
           console.log(p + ": " + item[p]);
      }
    }
    

    这应该返回一个属性和值的列表,包括年龄。

    【讨论】:

    • aah 好的,那他应该使用标签 qtcreator !无论如何我都会留下答案,也许它可以帮助其他人。
    • 您也可以提及JSON.stringify(object),但由于某些原因,这似乎并不总是有效。
    猜你喜欢
    • 2013-01-30
    • 2010-11-17
    • 2011-08-21
    • 1970-01-01
    • 2018-12-12
    • 2014-12-09
    • 1970-01-01
    • 2020-09-17
    • 2021-05-25
    相关资源
    最近更新 更多