Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
6.8, 6.9
-
None
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
Gerrit Reviews
For Gerrit Dashboard: QTBUG-132283 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
615323,12 | PropertyMap: Rework some metaObject and property cache interactions | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |