summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qproperty
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-04-29 11:53:18 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-30 19:39:42 +0200
commit709648993c1ea5f6b46ebe8bfd0f27d75c9b4e95 (patch)
treed55a7e97258fb9192f50abb85e93ba0ea4855d01 /tests/auto/corelib/kernel/qproperty
parent0c4bc39002763d2b0298586674a774821f52aa00 (diff)
Fix crash when using QProperty<T>::setBinding(Functor ...)
We must move the functor properly into the binding object, otherwise we end up with stale pointers as pointed out by ASAN. Change-Id: Icd84f4c113dd48e1e3e2d744abac0902cdf9339e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qproperty')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 488ecacb8d..8894260988 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -68,6 +68,7 @@ private slots:
void genericPropertyBinding();
void genericPropertyBindingBool();
void staticChangeHandler();
+ void setBindingFunctor();
};
void tst_QProperty::functorBinding()
@@ -674,6 +675,17 @@ void tst_QProperty::staticChangeHandler()
QCOMPARE(t.observedValues, values);
}
+void tst_QProperty::setBindingFunctor()
+{
+ QProperty<int> property;
+ QProperty<int> injectedValue(100);
+ // Make sure that this picks the setBinding overload that takes a functor and
+ // moves it correctly.
+ property.setBinding([&injectedValue]() { return injectedValue.value(); });
+ injectedValue = 200;
+ QCOMPARE(property.value(), 200);
+}
+
QTEST_MAIN(tst_QProperty);
#include "tst_qproperty.moc"