QProperty: Downgrade assert in noSelfDependencies to warning
We call evaluateRecursive_inline in setBinding, which in turns runs the noSelfDependecies check. However, creating a binding resuting in a binding loop must not crash, but instead result in the binding entering an error state. To prevent a crash caused by the assert in debug builds of Qt, we replace the assert with a warning for now. A better approach in the future would be to ensure that we only run the check in cases where we are sure that a self-dependency is really a fatal error. Pick-to: 6.2 Change-Id: I58158864ed81fa907132a4e7d6667c9b529e7e64 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
This commit is contained in:
parent
8ade7d3a3e
commit
fd30881989
@ -744,7 +744,10 @@ void QPropertyObserverPointer::noSelfDependencies(QPropertyBindingPrivate *bindi
|
||||
// See also comment in notify()
|
||||
while (observer) {
|
||||
if (QPropertyObserver::ObserverTag(observer->next.tag()) == QPropertyObserver::ObserverNotifiesBinding)
|
||||
Q_ASSERT(observer->binding != binding);
|
||||
if (observer->binding == binding) {
|
||||
qCritical("Property depends on itself!");
|
||||
break;
|
||||
}
|
||||
|
||||
observer = observer->next.data();
|
||||
}
|
||||
|
@ -113,6 +113,8 @@ private slots:
|
||||
void notify();
|
||||
|
||||
void bindableInterfaceOfCompatPropertyUsesSetter();
|
||||
|
||||
void selfBindingShouldNotCrash();
|
||||
};
|
||||
|
||||
void tst_QProperty::functorBinding()
|
||||
@ -1847,6 +1849,13 @@ void tst_QProperty::bindableInterfaceOfCompatPropertyUsesSetter()
|
||||
QCOMPARE(obj.setCompatCalled, 1);
|
||||
}
|
||||
|
||||
void tst_QProperty::selfBindingShouldNotCrash()
|
||||
{
|
||||
QProperty<int> i;
|
||||
i.setBinding([&](){ return i+1; });
|
||||
QVERIFY(i.binding().error().hasError());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QProperty);
|
||||
|
||||
#undef QT_SOURCE_LOCATION_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user