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

Incomplete and inconsistent type checking for QML lists

    XMLWordPrintable

Details

    • aeabdb938 (dev), c9c1a0840 (6.8), 2b3a164cb (6.7), 3e7abefc4 (tqtc/lts-6.5)

    Description

      Code

      import QtQuick
      
      Window {
          id: root
          width: 800
          height: 600
          visible: true
      
          Item { id: rawItem }
          QtObject { id: rawObj }
      
          property int number: Qt.point(100, 100) // Compiler warning (Expected)
          property list<Item> itemList: [
              rawItem,
              rawObj // No compiler warning (NOT expected)
          ]
      
          function testAssignment() {
              root.itemList[0] = rawItem
              root.itemList[1] = rawObj // Compiler warning (Expected)
          }
      
          function printList() {
              for (let i = 0; i < root.itemList.length; ++i)
                  console.log(root.itemList[i])
          }
      
          Component.onCompleted: {
              console.log("# Before imperative assignment")
              root.printList() // Null 2nd item (Expected)
      
              root.testAssignment()
      
              console.log("# After imperative assignment")
              root.printList() // Non-null 2nd item (NOT expected)
          }
      }
      

       

      Outcomes

      • Initialization of `root.number` produces a qmlsc warning (Expected)
        Warning: Main.qml:12:23: Cannot assign binding of type QPointF to int [incompatible-type]
            property int number: Qt.point(100, 100) // Compiler warning (Expected)
                                 ^^^^^^^^^^^^^^^^^^
        
      • Initialization of `root.itemList` does not produce a qmlsc warning (Not expected)
      • function testAssignment() produces a qmlsc warning (Expected, although the warning cursor is a bit off)
        Warning: Main.qml:21:2: Could not compile function testAssignment: Cannot convert from  to QQuickItem [compiler]
            }
            ^
        
      • printList() produces different results at runtime (Not expected - Both calls should print the same thing):
        qml: # Before imperative assignment
        qml: QQuickItem(0x158c6ed33a0)
        qml: null
        qml: # After imperative assignment
        qml: QQuickItem(0x158c6ed33a0)
        qml: QObject(0x158c50ce1f0)
        

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes