Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.3.0, 5.5.0, 5.7.0
-
None
-
windows 7
-
16b680b734101db0cb4fa3f313ac563a509ddff4
Description
The problem was found since i import qml with dynamic-property, maybe in version 5.2 or 5.3, but still exists in the latest version 5.5.
Following is my c++ code:
QQmlPropertyMap* map = new QQmlPropertyMap;
map->insert("abc", false);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("myObject", map);
...
and then, the qml code:
Connections {
target: myObject
onAbcChanged:
}
mouseArea.onClicked:
{ myObject.abc = true; console.log("mouse clicked!") }last, the result in console:
qml: abc changed! true
qml: mouse clicked!
qml: abc changed! true
qml: mouse clicked!
qml: abc changed! true
qml: mouse clicked!
......
For this problem, i read the Qt's source code, and catched a probable reason. i corrected the error logic in souce code ,and recompiled it, achived a fixed version of QtQmld.dll. With the fixed version, my problem had been resolved.
Following is the source code:
file-> src/qtdeclarative/src/qml/qml/qqmlopenmetaobject.cpp
function-> metaCall, line->242
241 else if (c == QMetaObject::WriteProperty) {
242 if (propId <= d->data.count() || d->data[propId].first != *reinterpret_cast<QVariant *>(a[0]))
In line 242, the propId of existed property will always be lower than d->data.count(), so the property will always be written and signal will be emitted.
I modified "<=" to be ">=", and then, for existed property, value comparison will be done, and signal will not be emitted by qml-same-value. for new-added property, its propId will be larger than or equals with data.count(), value will be written and signal will be emitted.