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

Destroying an item crashes ListView

    XMLWordPrintable

Details

    • 1e3924d8f585dd9099eb74ffbc17950c693d14da

    Description

      Run the following example and click one of the items => crash. The test case looks silly, but ListView really shouldn't crash that easily...

      import QtQuick 2.2
      import QtQml.Models 2.1
      import QtQuick.Window 2.1
      
      Window {
          id: window
      
          width: 360
          height: 360
          visible: true
      
          ListView {
              anchors.fill: parent
              anchors.margins: 20
              spacing: 20
      
              model: ObjectModel {
                  MouseArea {
                      width: 160; height: 160
                      Rectangle { anchors.fill: parent; color: "tan" }
                      onClicked: destroy()
                  }
                  MouseArea {
                      width: 160; height: 160
                      Rectangle { anchors.fill: parent; color: "thistle" }
                      onClicked: destroy()
                  }
                  MouseArea {
                      width: 160; height: 160
                      Rectangle { anchors.fill: parent; color: "tomato" }
                      onClicked: destroy()
                  }
              }
          }
      }
      

      A more realistic use case is in Qt Quick Controls 2, namely TabBar and SwipeView. Both use ListView + ObjectModel internally, and offer an API to add/insert/move/remove items dynamically. This means that items may get destroyed while the view and model are still alive.

      Attachments

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

        Activity

          People

            liaqi Liang Qi
            jpnurmi J-P Nurmi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes