From d7f7d84365dcec364e0248c51f557dd9c59f5f47 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 4 Jun 2021 17:11:14 +0200 Subject: [PATCH] QProperty: Refresh the observers after evaluating bindings Evaluating bindings may actually break bindings, and remove observers. Therefore, we need to re-fetch for notifying afterwards. Fixes: QTBUG-94220 Change-Id: I96a78a825f983f58f1a574bf886e643f54453fdc Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qproperty.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 22e9e2d6e0..32c73278ec 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -546,16 +546,21 @@ void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr if (isNotificationDelayed()) return; QPropertyBindingDataPointer d{this}; - QPropertyObserverPointer observer = d.firstObserver(); - if (!observer) - return; - auto *delay = groupUpdateData; - if (delay) { - delay->addProperty(this, propertyDataPtr); + + if (QPropertyObserverPointer observer = d.firstObserver()) { + auto *delay = groupUpdateData; + if (delay) { + delay->addProperty(this, propertyDataPtr); + return; + } + observer.evaluateBindings(); + } else { return; } - observer.evaluateBindings(); - observer.notify(propertyDataPtr); + + // evaluateBindings() can trash the observers. We need to re-fetch here. + if (QPropertyObserverPointer observer = d.firstObserver()) + observer.notify(propertyDataPtr); } int QPropertyBindingDataPointer::observerCount() const