Properties 由点符号表示的QML属性提示 A类{ QListchild; Q_可调用B*getChild(intidx){return child.at(idx);} } B类{ 智力年龄; } 在QML中: 项目{ A{ id:a; } Componet.onCompleted:{ console.log:a.getChild(0).age; } }
我有两个班A和B。 我已经注册了main.cpp中的A类和B类。Properties 由点符号表示的QML属性提示 A类{ QListchild; Q_可调用B*getChild(intidx){return child.at(idx);} } B类{ 智力年龄; } 在QML中: 项目{ A{ id:a; } Componet.onCompleted:{ console.log:a.getChild(0).age; } },properties,qml,qlist,Properties,Qml,Qlist,我有两个班A和B。 我已经注册了main.cpp中的A类和B类。 我可以获得正确的值,但我希望在a.getChild(0)之后,如果我不知道类B具有什么属性,就能够通过点表示法获得提醒。是的,您可以在Qml中迭代对象B的所有属性。但您将获得所有属性,包括信号和插槽 在QML中: class A{ QList<B *>child; Q_INVOKABLE B * getChild(int idx) {return child.at(idx);} } class B{
我可以获得正确的值,但我希望在a.getChild(0)之后,如果我不知道类B具有什么属性,就能够通过点表示法获得提醒。是的,您可以在Qml中迭代对象B的所有属性。但您将获得所有属性,包括信号和插槽 在QML中:
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;
}
}
这将返回属性和值的列表,包括年龄 啊,好吧,那他应该用标签了!无论如何,我会留下答案,也许它对其他人有帮助。你也可以提到
JSON.stringify(object)
,尽管出于某些原因,这似乎并不总是有效的。
Item{
A {
id: a;
}
Componet.onCompleted: {
var bItem = a.getChild(0)
for (var p in bItem )
console.log(p + ": " + item[p]);
}
}