0
votes
ComboBox {  
    anchors.fill: parent  
    model: rangeList  
    currentIndex: 1
}

rangeList contains 1,2,3 as data and currentIndex is 1. But when I run the UI it always takes currentindex as 0. Can anyone tell why it is taking currentIndex as 0 instead of 1.

ListModel { id: rangeList 
    ListElement { name: "1" }
    ListElement { name: "2" }
    ListElement { name: "3" }
    ListElement { name: "4" }
}
1
I cannot reproduce your problem. Please provide the minimal part of your code that really reproduces your error. I set the model to [1,2,3] and as expected, the initial selection is 2 - derM
Please show how you create the rangeList. I guess the problem resides within that piece of code, hidden from us. - derM
Have you tried the code, exactly as you posted it? My ComboBox shows correctly 2 upon startup when I copy both into the same Window. - derM
Have you checked the output for any warning from the QML engine ? - Benjamin T

1 Answers

0
votes

You can try setting the index using onCompleted which is emitted after the object has been instantiated.

ComboBox {  
    anchors.fill: parent  
    model: rangeList  
    Component.onCompleted: currentIndex = 1
}