我做了非常简单的 QAbstractListModel 例子。这个例子也在这个链接上展示:http: //doc.qt.io/qt-5/qtquick-models-abstractitemmodel-example.html。一个程序结果是这样的:
程序结果 我在 view.qml 上做了一点改变,像这样
ComboBox {
id:mycombo
width: 200; height: 250
model: myModel
textrole:"type"
onCurrentTextChanged: {
console.log(mycombo.model.get(currentIndex).size);
}
}
在这里,Combobox 显示动物类型。但我想在 onCurrentTextChanged 事件时写入“大小”值。但我无法获得类型值。