Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-32838

Qml ListView currentIndex wrong when assigning empty model

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.2.0 Beta1
    • 4.8.5, 5.1.1
    • None
    • Mac OS X 10.6
    • 290dc6caf65aeecaceb5a67b55cb33f0b059f98a

    Description

      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 obviously not a valid index for an
      empty model. It's the same behavior in QtQuick 1 and QtQuick 2.

      The same problem occurs when assigning an empty Qml ListModel.

      Attachments

        For Gerrit Dashboard: QTBUG-32838
        # Subject Branch Project Status CR V

        Activity

          People

            njeisecke Nils Jeisecke
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes