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

QML tools: More warnings about incompatible types

XMLWordPrintable

      Consider different ways we could (accidentally) shove incompatible types into strongly-typed properties.

       

      Code

      import QtQuick
      
      Window {
          id: window
          width: 400
          height: 300
          visible: true
      
          property Item itemProp: window // Runtime + qmlsc + qmllint + qmlls warnings
      
          property list<Item> itemList: [
              window // Runtime warning only
          ]
      
          function assignItemProp() {
              window.itemProp = window // Runtime + qmlsc warnings only
          }
      
          function assignItemList() {
              window.itemList[0] = window // Runtime + qmlsc warnings only
          }
      
          Component.onCompleted: {
              assignItemProp()
              assignItemList()
          }
      }
      

       

      Outcomes
      We get a mixed bag of warnings:

      Incompatible assignment Runtime warning qmllint/qmlls warning qmlsc warning
      itemProp declarative initialization ✔️ ✔️ ✔️
      itemList declarative initialization ✔️
      itemProp imperative assignment ✔️ ✔️
      itemList imperative assignment ✔️ ✔️

       

      Suggestion

      Fill the table above with ticks, if all types involved are known at edit/build time.

       

      Use case
      A customer upgraded to Qt 6.8 and they now see new incompatible-type warnings across their project (thanks to the fix for QTBUG-127343), like:

      qt.qml.list.incompatible: Cannot append Main_QMLTYPE_0(0x26857677a50) to a QML list of QQuickItem*
      

      However, there is no easy way to track down (and fix) the cause of these warnings.

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

            qtqmlteam Qt Qml Team User
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes