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

Accessing ListView's currentItem after a model change can segfault

    XMLWordPrintable

Details

    • 9b25a6f39ee59fe1bb4352a5f2e4ef4a91f1f2c3

    Description

      The following QML app crashes after you click somewhere:

      import QtQuick 2.0

      Rectangle {
      ListModel {
      id: model
      ListElement { }
      }
      ListView {
      id: list
      model: model
      delegate: Item {
      }
      }
      MouseArea {
      anchors.fill: parent
      onClicked:

      { // remove the only item model.remove(0) console.log("Should be null: " + list.currentItem) }

      }
      }

      After the model operation the currentItem should be null (as there are no items left). But the change is pending and executed when accessing the currentItem property. An error in QQuickItemView::currentItem() leads to a crash.

      The same behaviour does not occur in QtQuick1.

      I attached a patch against Qt 5.0.1 which works for me.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            carochao Caroline Chao (Inactive)
            simh Steffen Imhof
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes