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

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

    XMLWordPrintable

Details

    Description

      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

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-133052
          # Subject Branch Project Status CR V

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change