C++ QAbstractListModel到Combobox,选择值b时如何获取值a
我制作了一个非常简单的QAbstractListModel示例。这个示例也出现在这个链接上:。程序结果如下所示: 我在view.qml上对它做了一些更改,如下所示C++ QAbstractListModel到Combobox,选择值b时如何获取值a,c++,qt,qml,qabstractlistmodel,C++,Qt,Qml,Qabstractlistmodel,我制作了一个非常简单的QAbstractListModel示例。这个示例也出现在这个链接上:。程序结果如下所示: 我在view.qml上对它做了一些更改,如下所示 ComboBox { id:mycombo width: 200; height: 250 model: myModel textrole:"type" onCurrentTextChanged: { console.log(mycombo.model.get(currentIndex).size); } } 在这里,组
ComboBox {
id:mycombo
width: 200; height: 250
model: myModel
textrole:"type"
onCurrentTextChanged: {
console.log(mycombo.model.get(currentIndex).size);
}
}
在这里,组合框显示动物类型。但我想在onCurrentTextChanged事件时写入“大小”值。但我无法获取类型值 我认为您的cpp模型实现失败了。 因为当我使用qml模型时,它的工作方式应该是:
ListModel {
id: myModel
ListElement{
type: "mouse"
size: "small"
}
ListElement{
type: "cat"
size:"medium"
}
ListElement{
type: "elephant"
size:"large"
}
}
ComboBox {
id:mycombo
width: 200; height: 250
model: myModel
textRole:"type"
onCurrentTextChanged: {
console.log(mycombo.model.get(currentIndex).size);
}
}
输出:
qml: small
qml: medium
qml: large