PDA

View Full Version : ComboBox default value



neda
5th April 2016, 07:10
Hi,
I want to set default value for combobox. But "find" method returns -1.

MyComboBox{
id:cmbZoom
model:XmlListModel {
id: xmlZoomModel
source: "files/zoom.XML"
query: "/tbl_zoomCalib/record"
XmlRole { name: "text"; query: "@zoom/string()" }
XmlRole { name: "value"; query: "@number/string()" }
}
textRole: "text"
onCurrentIndexChanged: {
myXML.newZoom=xmlZoomModel.get(currentIndex).text;
}
Component.onCompleted: {
currentIndex=cmbZoom.find("20");
}
}

anda_skoa
5th April 2016, 09:40
You are calling find() when the combo box is completed, which is likely before it has data.
You probably want to do that when the data has been loaded, see XmlListModel's status property.

Cheers,
_