aboutsummaryrefslogtreecommitdiff
path: root/lib/qt_connection_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/qt_connection_util.h')
-rw-r--r--lib/qt_connection_util.h28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/qt_connection_util.h b/lib/qt_connection_util.h
index c6fa037a..46294499 100644
--- a/lib/qt_connection_util.h
+++ b/lib/qt_connection_util.h
@@ -19,12 +19,7 @@ namespace _impl {
decorated_slot_tt<ArgTs...> decoratedSlot,
Qt::ConnectionType connType)
{
- // See https://bugreports.qt.io/browse/QTBUG-60339
-#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
- auto pc = std::make_shared<QMetaObject::Connection>();
-#else
auto pc = std::make_unique<QMetaObject::Connection>();
-#endif
auto& c = *pc; // Resolve a reference before pc is moved to lambda
// Perfect forwarding doesn't work through signal-slot connections -
@@ -73,6 +68,17 @@ namespace _impl {
}),
connType);
}
+
+ // TODO: get rid of it as soon as Apple Clang gets proper deduction guides
+ // for std::function<>
+ // ...or consider using QtPrivate magic used by QObject::connect()
+ // ...for inspiration, also check a possible std::not_fn implementation
+ // at https://en.cppreference.com/w/cpp/utility/functional/not_fn
+ template <typename FnT>
+ inline auto wrap_in_function(FnT&& f)
+ {
+ return typename function_traits<FnT>::function_type(std::forward<FnT>(f));
+ }
} // namespace _impl
/*! \brief Create a connection that self-disconnects when its "slot" returns true
@@ -90,7 +96,7 @@ inline auto connectUntil(SenderT* sender, SignalT signal, ContextT* context,
const FunctorT& slot,
Qt::ConnectionType connType = Qt::AutoConnection)
{
- return _impl::connectUntil(sender, signal, context, wrap_in_function(slot),
+ return _impl::connectUntil(sender, signal, context, _impl::wrap_in_function(slot),
connType);
}
@@ -100,8 +106,13 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal,
ContextT* context, const FunctorT& slot,
Qt::ConnectionType connType = Qt::AutoConnection)
{
+#if QT_VERSION_MAJOR >= 6
+ return QObject::connect(sender, signal, context, slot,
+ Qt::ConnectionType(connType
+ | Qt::SingleShotConnection));
+#else
return _impl::connectSingleShot(
- sender, signal, context, wrap_in_function(slot), connType);
+ sender, signal, context, _impl::wrap_in_function(slot), connType);
}
// Specialisation for usual Qt slots passed as pointers-to-members.
@@ -114,11 +125,12 @@ inline auto connectSingleShot(SenderT* sender, SignalT signal,
{
// TODO: when switching to C++20, use std::bind_front() instead
return _impl::connectSingleShot(sender, signal, receiver,
- wrap_in_function(
+ _impl::wrap_in_function(
[receiver, slot](const ArgTs&... args) {
(receiver->*slot)(args...);
}),
connType);
+#endif
}
/*! \brief A guard pointer that disconnects an interested object upon destruction