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

Using `in` in a QQmlPropertyMap inserts keys

    XMLWordPrintable

Details

    Description

      I'm struggling with finding a clean way to check from QML whether a QQmlPropertyMap contains a key or not.

      On https://codereview.qt-project.org/c/qt/qtdeclarative/+/611881 Fabian suggested to just use JS' in operator, but that doesn't seem to work properly: if the map is not frozen, it will always insert keys, and therefore always report true.

      Consider a QQmlPropertyMap just containing the key key1, then this:

                  console.log("key1" in myMap)
                  console.log("key2" in myMap)
                  console.log("this certainly does not exist" in myMap)
                  console.log("destroyed" in myMap)
                  console.log("keys" in myMap)
      
                  console.log("Iterating:")
                  for (const property in myMap) {
                    console.log(`${property}: ${myMap[property]}`);
                  }
      

      prints out

      qml: true
      qml: true
      qml: true
      qml: true
      qml: true
      qml: Iterating:
      qml: objectName: 
      qml: key1: 42
      qml: key2: undefined
      qml: this certainly does not exist: undefined
      qml: destroyed: undefined
      qml: objectNameChanged: function() { [native code] }
      qml: valueChanged: function() { [native code] }
      qml: keys: function() { [native code] }
      qml: contains: function() { [native code] }
      qml: __0: function() { [native code] }
      qml: __1: function() { [native code] }
      qml: __2: function() { [native code] }
      qml: __3: function() { [native code] }
      

      Attachments

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

        Activity

          People

            olivier.decanniere Olivier De Cannière
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change