How to update combobox values dynamically?
I would like to have two comboboxes and the values of the second one should be dependant of the option chosen for the first combobox. However, I have not been able to figure out how to make this happen.
As I understand previously it has been able to refresh the combobox values from C++ like http://stackoverflow.com/questions/8293447/how-to-refresh-contents-of-qcombobox-in-qtableview here. My understanding of the context property is pretty thin but should this be implementable also for Sailfish Silica? http://stackoverflow.com/questions/18616497/how-to-use-models-with-qml
If I understood correctly I would need a signal which signals the change in the selection of the first combobox and somehow update or refresh the second combobox in QML.
Here is my code for comboboxes if it is of any help. I would also appreciate a tutorial on this bridge over C++ and QML. Somehow I found the Qt documentation on this matter rather superficial.
ComboBox {
id: comboBox1
width: parent.width
x: Theme.paddingMedium
label: "Combobox1: "
currentIndex: { comboBox_Olio.getCombo1Idx() }
menu: ContextMenu {
MenuItem { text: "Option A"}
MenuItem { text: "Option B"}
}
onCurrentIndexChanged: {
comboBox_Olio.setComboBox1Value(currentIndex)
console.log(currentIndex)
}
}
ComboBox {
id: comboBox2
width: parent.width
x: Theme.paddingMedium
label: "Combobox2: "
menu: ContextMenu {
Repeater {
model: comboBox_Olio.getComboBoxValues()
MenuItem { text: modelData}
}
}
onCurrentIndexChanged: {
comboBox_Olio.setComboBox2( value )
}
}