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

ListModel uses modelData when only one role is set for ListElement

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 5.12.3
    • Quick: Other
    • None
    • All

       

      It seems that ListModel now also sets the modelData property for delegates, in case there's only one role for each ListElement. Before, modelData was always undefined for ListModel types. This caused an issue in our application. See this example code:

      import QtQuick 2.9
      import QtQuick.Window 2.2
      
      Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("ListModel with modelData")
      
        ListView {
          anchors.fill: parent
          model:   ListModel {
            ListElement {
                name: "Apple"
            }
            ListElement {
                name: "Orange"
            }
            ListElement {
                name: "Banana"
            }
          }
      
          delegate: Text {
            text: modelData
          }
        }
      }
      

      This example prints this names for the delegate text. When adding another role to a ListElement, modelData becomes undefined. Was this change planned, or do you consider this a bug?

       

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            GTDev Günther Teufl
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes