diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-10-15 13:51:48 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-12-22 19:16:47 +0200 |
commit | afddb327bd866ac693e475901d4d10acc6c83757 (patch) | |
tree | e6668b16415fa788606b986bd90a230a77a25321 /src/corelib/kernel | |
parent | 061a2012ad70159ddb28a28344f67637bc965f18 (diff) |
QObject: assert connection type isn't UniqueConnection for lambdas
An assert is harder to miss than a warning, which makes it more likely
to get fixed. Thanks to Mårten Nordheim for the idea.
Add the assert in inline code so that users compiling their code in
debug mode (or with -DQT_FORCE_ASSERTS) can hit the assert even when
built agaist a release build of Qt (not everyone compile their code with
a debug build of Qt). Thanks to Giuseppe D'Angelo for the idea.
Pick-to: 6.7 6.6 6.5
Task-number: QTBUG-115125
Change-Id: I2935d32ea5a2c288d7a836abbae66ac53cb5ab2f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qobject.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 9916626a3c..713a62c249 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -241,8 +241,13 @@ public: types = QtPrivate::ConnectionTypes<typename SignalType::Arguments>::types(); void **pSlot = nullptr; - if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) + if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) { pSlot = const_cast<void **>(reinterpret_cast<void *const *>(&slot)); + } else { + Q_ASSERT_X((type & Qt::UniqueConnection) == 0, "", + "QObject::connect: Unique connection requires the slot to be a pointer to " + "a member function of a QObject subclass."); + } return connectImpl(sender, reinterpret_cast<void **>(&signal), context, pSlot, QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)), |