From 709648993c1ea5f6b46ebe8bfd0f27d75c9b4e95 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 29 Apr 2020 11:53:18 +0200 Subject: Fix crash when using QProperty::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 --- tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/auto/corelib/kernel/qproperty') 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 property; + QProperty 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" -- cgit v1.2.3