[Solved] Method or Function to load a ComboBox model dynamically ?
-
You can do this inline by:
@ ComboBox {
model: [ "item1,item2,item3" ]
}@But I'd like to be able to do something more like:
@ VisualItemModel {
id: itemModelThing { myComboModelString: "item1,item2,item3" }
}ListView {
anchors.fill: parent
model: itemModel
}
Thing.qml
Rectangle {
id: thingproperty string myComboModelString
ComboBox {
model: myComboModelString
}
}
@So is there a method or function I'm missing that will take a delimited string and load a model? Or do I have to create a function in either QML/C++ myself to accomplish this?
-
I'm quite sure to got what you want to do.
That's because, your first snippet code it's wrong. You cannot do:
@
ComboBox {
model: [ "item1,item2,item3" ]
}
@
But you should do the following:
@
ComboBox {
model: [ "item1", "item2", "item3" ]
}
@And from what I know there no functions for splitting a delimited string into a list from QML side. But you can do on C++ using QString::split method, and from C++ you can return directly the QStringList to the model property of ComboBox:
@
ComboBox {
model: cppObject.splitString( myComboModelString )
}
@And from C++:
@
QStringList CppObject::splitString( QString myComboModelString ) {
return myComboModelString.split( "," );
}
@