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

False "Layout must be attached to Item elements" warning

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • 6.8
    • 6.7
    • QML: Tooling
    • None

    Description

      Consider the following QML code:

       

      import QtQuick
      import QtQuick.Layouts
      
      Item {
          property list<Item> knownItems: []
          property int foo: knownItems[0].Layout.preferredWidth
      } 

      qmllint warns

       

      Warning: test.qml:6:23: Layout must be attached to Item elements [Quick.attached-property-type]
          property int foo: knownItems[0].Layout.preferredWidth
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      However since knownItems is a list of Items knownItems[0] is an Item, so I expect Layout to be available, which it is at runtime. When changing the type from list<Item> to var the warning disappears.

      qtdeclarative commit 41a97f06981144ef80a3faf8925753f15c0ff3c6

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            nicolasfella Nicolas Fella
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes