6#include <QtCore/QObject>
7#include <QtCore/QPointer>
21template <
typename SmartSlotT>
22inline auto connectUntil(
auto* sender,
auto signal, QObject* context, SmartSlotT&& smartSlot,
25 auto* cHolder =
new QObject(context);
28 return QObject::connect(
29 sender, signal, cHolder,
30 [sl = std::forward<SmartSlotT>(smartSlot), cHolder]<
typename... Ts>
31 requires std::invocable<SmartSlotT, Ts...>
32 (
const Ts&... args)
mutable {
33 static_assert(std::is_same_v<
decltype(sl(args...)),
bool>);
41template <
typename ContextT,
typename SlotT>
42[[deprecated(
"Use QObject::connect() with Qt::SingleShotConnection, or QtFuture::connect()")]]
46 return QObject::connect(sender, signal, context, slot,
47 Qt::ConnectionType(connType | Qt::SingleShotConnection));
51
52
53
54
55
56
66 (*
this)->disconnect(subscriber);
A guard pointer that disconnects an interested object upon destruction.
ConnectionsGuard(ConnectionsGuard &&)=default
ConnectionsGuard(T *publisher, QObject *subscriber)
ConnectionsGuard & operator=(ConnectionsGuard &&)=default
auto connectSingleShot(auto *sender, auto signal, ContextT *context, SlotT slot, Qt::ConnectionType connType=Qt::AutoConnection)
Create a connection that self-disconnects after triggering on the signal.
auto connectUntil(auto *sender, auto signal, QObject *context, SmartSlotT &&smartSlot, Qt::ConnectionType connType=Qt::AutoConnection)
Create a connection that self-disconnects when its slot returns true.