[Interest] Qml ListView currentIndex behavior
Dmitry Ashkadov
dmitry.ashkadov at gmail.com
Mon Aug 5 19:46:14 CEST 2013
05.08.2013 20:58, Nils Jeisecke пишет:
> Hi list,
>
> when explicitly setting a view's model to an empty array (or an empty
> ListModel, C++-Model, etc.) the currentIndex property changes from -1
> to 0. Initializing the model property with an empty model works as
> expected.
>
> ---
>
> import QtQuick 2.0
>
> Rectangle {
> width: 360
> height: 360
>
> ListView {
> id: view
> anchors.fill: parent
> // model: [] // this works, currentIndex will be -1
> delegate: Text {
> text: modelData
> }
> }
>
> Text {
> anchors { right: parent.right }
> text: view.currentIndex
> MouseArea {
> anchors.fill: parent
> onClicked: view.model = [] // now currentIndex becomes 0
> }
> }
> }
>
> ---
>
> This looks like a bug to me because 0 is not a valid index for an
> empty model. It's the same behavior in QtQuick 1 and QtQuick 2.
>
> Any ideas?
If I understand right, in code "model: []" the brackets are a QML list
and it is empty. In code "view.model = []" the brackets are JS object of
type Array.
I think the next should work as expected:
ListModel { id: emptyModel }
...
onClicked: view.model = emptyModel
>
> Nils
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list