Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In Ubuntu SDK QML tutorial a simple currency converter is build. The complete QML source code can be found here. When working through the example I found the following snippet somewhat confusing, particularly line 92 where the index field is assigned to caller.currencyIndex.

ListView {
    clip: true
    width: parent.width
    height: parent.height - header.height
    model: currencies
    delegate: Standard {
        objectName: "popoverCurrencySelector"
        text: currency
        onClicked: {
            caller.currencyIndex = index // where does index come from?
            caller.input.update()
            hide()
        }
    }
}

I couldn't find any clue in the documentation where index is defined. What it should contain is absolutely obvious, but where does it come from? If it is a property of the Standard list view item it is nowhere documented.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

index is a property of the ListView delegate, not necessarily a ListItem. It represents the number of the currentItem. From the docs:

The index is exposed as an accessible index property. Properties of the model are also available depending upon the type of Data Model.

share|improve this answer
    
That was exactly the piece of documentation I was looking for! Would've never expected this to be a property of the delegate. –  ubuntudroid Mar 3 at 8:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.