QML: Don't crash when monitoring binding removal
There are more bindings kinds around.
Fixes: QTBUG-113353
Change-Id: If545f56bd61c238431883be3eb013841d96b18bb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 567130e2d0
)
This commit is contained in:
parent
70f2ef3788
commit
b6a75904d6
|
@ -551,14 +551,26 @@ void QObjectWrapper::setProperty(
|
|||
|
||||
if (Q_UNLIKELY(lcBindingRemoval().isInfoEnabled())) {
|
||||
if (auto binding = QQmlPropertyPrivate::binding(object, QQmlPropertyIndex(property->coreIndex()))) {
|
||||
Q_ASSERT(binding->kind() == QQmlAbstractBinding::QmlBinding);
|
||||
const auto qmlBinding = static_cast<const QQmlBinding*>(binding);
|
||||
const auto stackFrame = engine->currentStackFrame;
|
||||
qCInfo(lcBindingRemoval,
|
||||
"Overwriting binding on %s::%s at %s:%d that was initially bound at %s",
|
||||
object->metaObject()->className(), qPrintable(property->name(object)),
|
||||
qPrintable(stackFrame->source()), stackFrame->lineNumber(),
|
||||
qPrintable(qmlBinding->expressionIdentifier()));
|
||||
switch (binding->kind()) {
|
||||
case QQmlAbstractBinding::QmlBinding: {
|
||||
const auto qmlBinding = static_cast<const QQmlBinding*>(binding);
|
||||
qCInfo(lcBindingRemoval,
|
||||
"Overwriting binding on %s::%s at %s:%d that was initially bound at %s",
|
||||
object->metaObject()->className(), qPrintable(property->name(object)),
|
||||
qPrintable(stackFrame->source()), stackFrame->lineNumber(),
|
||||
qPrintable(qmlBinding->expressionIdentifier()));
|
||||
break;
|
||||
}
|
||||
case QQmlAbstractBinding::ValueTypeProxy:
|
||||
case QQmlAbstractBinding::PropertyToPropertyBinding: {
|
||||
qCInfo(lcBindingRemoval,
|
||||
"Overwriting binding on %s::%s at %s:%d",
|
||||
object->metaObject()->className(), qPrintable(property->name(object)),
|
||||
qPrintable(stackFrame->source()), stackFrame->lineNumber());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QQmlPropertyPrivate::removeBinding(object, QQmlPropertyIndex(property->coreIndex()));
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
|
||||
ListView {
|
||||
id: list
|
||||
property int i: 0
|
||||
|
||||
model: 1
|
||||
delegate: Item {
|
||||
id: cellRootID
|
||||
required property int index
|
||||
Timer {
|
||||
interval: 1
|
||||
running: true
|
||||
onTriggered: {
|
||||
cellRootID.index = index + 123
|
||||
list.i = cellRootID.index
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -459,9 +459,15 @@ void tst_qqmlbinding::bindingOverwriting()
|
|||
QQmlComponent c(&engine, testFileUrl("bindingOverwriting.qml"));
|
||||
QScopedPointer<QQuickItem> item {qobject_cast<QQuickItem*>(c.create())};
|
||||
QVERIFY(item);
|
||||
QCOMPARE(messageHandler.messages().size(), 2);
|
||||
|
||||
QQmlComponent c2(&engine, testFileUrl("bindingOverwriting2.qml"));
|
||||
QScopedPointer<QObject> o(c2.create());
|
||||
QVERIFY(o);
|
||||
QTRY_COMPARE(o->property("i").toInt(), 123);
|
||||
QCOMPARE(messageHandler.messages().size(), 3);
|
||||
|
||||
QLoggingCategory::setFilterRules(QString());
|
||||
QCOMPARE(messageHandler.messages().size(), 2);
|
||||
}
|
||||
|
||||
void tst_qqmlbinding::bindToQmlComponent()
|
||||
|
|
Loading…
Reference in New Issue