summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 6898fa717e..d1d3738879 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -143,6 +143,7 @@ private slots:
void exceptions();
void noDeclarativeParentChangedOnDestruction();
void deleteLaterInAboutToBlockHandler();
+ void mutableFunctor();
};
struct QObjectCreatedOnShutdown
@@ -6508,6 +6509,24 @@ void tst_QObject::noDeclarativeParentChangedOnDestruction()
#endif
}
+struct MutableFunctor {
+ int count;
+ MutableFunctor() : count(0) {}
+ int operator()() { return ++count; }
+};
+
+void tst_QObject::mutableFunctor()
+{
+ ReturnValue o;
+ MutableFunctor functor;
+ QCOMPARE(functor.count, 0);
+ connect(&o, &ReturnValue::returnInt, functor);
+ QCOMPARE(emit o.returnInt(0), 1);
+ QCOMPARE(emit o.returnInt(0), 2); // each emit should increase the internal count
+
+ QCOMPARE(functor.count, 0); // but the original object should have been copied at connect time
+}
+
// Test for QtPrivate::HasQ_OBJECT_Macro
Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value);
Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);