QML对象的列表属性类似于list:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Item{
children: [
Text {
id: name1
text: qsTr("text1")
},
Text {
id: name2
anchors.left: name1.right
anchors.leftMargin: 4
text: qsTr("text2")
}
]
Component.onCompleted: {
for(var i=0;i<children.length;i++)
{
console.log("text of label ",i,":",children[i].text)
}
}
}
}
列表包含在方括号中,以逗号隔开,当只有一个成员时,方括号可以省略。其访问方式类似于list用下标进行访问成员的内容。