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

modelData is lost when using a nested QML component inside a Repeater

XMLWordPrintable

    • 171076792 (dev), 8a8fb882b (6.9), 38efd99ac (6.8)

      Example:

      import QtQuick
      import QtQuick.Controls.Basic
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          Repeater {
              model: ['one', 'two']
              MyButton {
                  text: modelData
              }
          }
          component FirstComponent : Item {
              required property var control
          }
          component SecondComponent : FirstComponent {}
          component MyButton : Button {
              id: btn
              contentItem: SecondComponent {
                  id: myContentItem
                  control: btn
              }
          }
      }
      

      Description:

      MyButton has no required properties. I expect that this sample will work and that modelData will contain 'one' or 'two'. However, when I run it (I use Qt 6.6.1 and Qt 6.8.1), I get the following error: "ReferenceError: modelData is not defined."

      But if I replace SecondComponent with FirstComponent in MyButton.contentItem, or remove the id from contentItem, it works as I expect. And I don't understand why

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

            ulherman Ulf Hermann
            wd32 Ilya
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes