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

ListView: If code in delegate causes delegate to be removed, references break

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.11.1
    • None
    • Linux/X11

    Description

      If you press the "Reset before set" button you get an error, even though you expect that it will change the label text.

      qrc:/main.qml:27: ReferenceError: label is not defined
      

      I think it makes sense to keep the references working until the whole code block finishes.

      import QtQuick 2.9
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.2
      import QtQuick.Layouts 1.3
      
      Window {
          visible: true
          width: 640
          height: 480
      
          ColumnLayout {
              anchors.fill: parent
              Label {
                  id: label
                  text: "This text should change"
              }
              ListView {
                  id: listview
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  model: 1
                  delegate: Row {
                      Button {
                          text: "Reset before set (doesn't work)"
                          onClicked: {
                              listview.model = 0
                              label.text = "Changed"
                          }
                      }
                      Button {
                          text: "Set before reset (works)"
                          onClicked: {
                              label.text = "Changed"
                              listview.model = 0
                          }
                      }
                  }
              }
          }
      }
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            netcatkate Sarah K
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes