QObject: Do not register an observer when writing objectName property
Observers should only be registered when _reading_ the property. Otherwise we get binding loops. Change-Id: I974f6ea444fa7a5d333ed79eea6f34e3d757d169 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 9306db6d465a165ebe2edcbe5b0180f04d0c46ee) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2fd12c03cd
commit
3ce73dc0d6
@ -1320,7 +1320,7 @@ void QObject::doSetObjectName(const QString &name)
|
|||||||
|
|
||||||
d->extraData->objectName.removeBindingUnlessInWrapper();
|
d->extraData->objectName.removeBindingUnlessInWrapper();
|
||||||
|
|
||||||
if (d->extraData->objectName != name) {
|
if (d->extraData->objectName.valueBypassingBindings() != name) {
|
||||||
d->extraData->objectName.setValueBypassingBindings(name);
|
d->extraData->objectName.setValueBypassingBindings(name);
|
||||||
d->extraData->objectName.notify(); // also emits a signal
|
d->extraData->objectName.notify(); // also emits a signal
|
||||||
}
|
}
|
||||||
@ -1338,7 +1338,7 @@ void QObject::setObjectName(QAnyStringView name)
|
|||||||
|
|
||||||
d->extraData->objectName.removeBindingUnlessInWrapper();
|
d->extraData->objectName.removeBindingUnlessInWrapper();
|
||||||
|
|
||||||
if (d->extraData->objectName != name) {
|
if (d->extraData->objectName.valueBypassingBindings() != name) {
|
||||||
d->extraData->objectName.setValueBypassingBindings(name.toString());
|
d->extraData->objectName.setValueBypassingBindings(name.toString());
|
||||||
d->extraData->objectName.notify(); // also emits a signal
|
d->extraData->objectName.notify(); // also emits a signal
|
||||||
}
|
}
|
||||||
|
@ -8197,6 +8197,16 @@ void tst_QObject::objectNameBinding()
|
|||||||
QObject obj;
|
QObject obj;
|
||||||
QTestPrivate::testReadWritePropertyBasics<QObject, QString>(obj, "test1", "test2",
|
QTestPrivate::testReadWritePropertyBasics<QObject, QString>(obj, "test1", "test2",
|
||||||
"objectName");
|
"objectName");
|
||||||
|
|
||||||
|
const QPropertyBinding<QString> binding([]() {
|
||||||
|
QObject obj2;
|
||||||
|
obj2.setObjectName(QLatin1String("no loop"));
|
||||||
|
return obj2.objectName();
|
||||||
|
}, {});
|
||||||
|
obj.bindableObjectName().setBinding(binding);
|
||||||
|
|
||||||
|
QCOMPARE(obj.objectName(), QLatin1String("no loop"));
|
||||||
|
QVERIFY2(!binding.error().hasError(), qPrintable(binding.error().description()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace EmitToDestroyedClass {
|
namespace EmitToDestroyedClass {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user