QObject: Do not register an observer when writing objectName property
Observers should only be registered when _reading_ the property. Otherwise we get binding loops. Pick-to: 6.6 6.5 Change-Id: I974f6ea444fa7a5d333ed79eea6f34e3d757d169 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
7c9e61a3fe
commit
9306db6d46
@ -1321,7 +1321,7 @@ void QObject::doSetObjectName(const QString &name)
|
||||
|
||||
d->extraData->objectName.removeBindingUnlessInWrapper();
|
||||
|
||||
if (d->extraData->objectName != name) {
|
||||
if (d->extraData->objectName.valueBypassingBindings() != name) {
|
||||
d->extraData->objectName.setValueBypassingBindings(name);
|
||||
d->extraData->objectName.notify(); // also emits a signal
|
||||
}
|
||||
@ -1339,7 +1339,7 @@ void QObject::setObjectName(QAnyStringView name)
|
||||
|
||||
d->extraData->objectName.removeBindingUnlessInWrapper();
|
||||
|
||||
if (d->extraData->objectName != name) {
|
||||
if (d->extraData->objectName.valueBypassingBindings() != name) {
|
||||
d->extraData->objectName.setValueBypassingBindings(name.toString());
|
||||
d->extraData->objectName.notify(); // also emits a signal
|
||||
}
|
||||
|
@ -8197,6 +8197,16 @@ void tst_QObject::objectNameBinding()
|
||||
QObject obj;
|
||||
QTestPrivate::testReadWritePropertyBasics<QObject, QString>(obj, "test1", "test2",
|
||||
"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 {
|
||||
|
Loading…
Reference in New Issue
Block a user