summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qproperty.cpp15
-rw-r--r--src/corelib/kernel/qproperty_p.h4
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp9
3 files changed, 28 insertions, 0 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index 0534749afa..686ec484ca 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -1667,4 +1667,19 @@ void restoreBindingStatus(BindingEvaluationState *status)
bindingStatus.currentlyEvaluatingBinding = status;
}
+namespace QtPrivate {
+/*!
+ \internal
+ This function can be used to detect whether we are currently
+ evaluating a binding. This can e.g. be used to defer the allocation
+ of extra data for a QPropertyBindingStorage in a getter.
+ Note that this function accesses TLS storage, and is therefore soemwhat
+ costly to call.
+ */
+bool isAnyBindingEvaluating()
+{
+ return bindingStatus.currentlyEvaluatingBinding != nullptr;
+}
+} // namespace QtPrivate end
+
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index 6ff1e8e71e..27cb8c907f 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -59,6 +59,10 @@
QT_BEGIN_NAMESPACE
+namespace QtPrivate {
+ Q_CORE_EXPORT bool isAnyBindingEvaluating();
+}
+
// Keep all classes related to QProperty in one compilation unit. Performance of this code is crucial and
// we need to allow the compiler to inline where it makes sense.
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 7de6458406..3b656dae25 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -1140,6 +1140,15 @@ void tst_QProperty::testNewStuff()
QCOMPARE(object.bindableFoo().value(), 111);
object.bindableFoo().setValue(24);
QCOMPARE(object.foo(), 24);
+
+ auto isCurrentlyEvaluatingBinding = []() {
+ return QtPrivate::isAnyBindingEvaluating();
+ };
+ QVERIFY(!isCurrentlyEvaluatingBinding());
+ QProperty<bool> evaluationDetector {false};
+ evaluationDetector.setBinding(isCurrentlyEvaluatingBinding);
+ QVERIFY(evaluationDetector.value());
+ QVERIFY(!isCurrentlyEvaluatingBinding());
}
void tst_QProperty::qobjectObservers()