Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.2, 4.8.0
-
None
-
0fdd97f613af6ae255e9cd1470ad8d4d67091dd7
Description
The following code does not work as expected. QML thinks that keys is a property that needs to be added instead of the Q_INVOKABLE function.
test.cpp
QDeclarativePropertyMap *test = new QDeclarativePropertyMap; test->insert("prop", QVariant(2)); engine()->rootContext()->setContextProperty("test", test);
test.qml
console.log(test.keys())
This code results in:
TypeError: Result of expression 'test.keys' [undefined] is not a function.
From what I was able to find, the function QDeclarativeOpenMetaObject::createProperty is called with keys, and then the property 'keys' is auto created. As a work around I overloaded the createProperty in QDeclarativePropertyMap and just checked if the created property is 'keys' and return a -1, but its not nice. I just dont know enough about the internals of the script and qml engines to propose a cleaner solution.