aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/connection.h')
-rw-r--r--lib/connection.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/connection.h b/lib/connection.h
index c7e28282..7adab883 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -48,6 +48,26 @@ namespace QMatrixClient
class DownloadFileJob;
class SendToDeviceJob;
+ /** Create a single-shot connection that triggers on the signal and
+ * then self-disconnects
+ *
+ * Only supports DirectConnection type.
+ */
+ template <typename SenderT1, typename SignalT,
+ typename ReceiverT2, typename SlotT>
+ inline auto connectSingleShot(SenderT1* sender, SignalT signal,
+ ReceiverT2* receiver, SlotT slot)
+ {
+ QMetaObject::Connection connection;
+ connection = QObject::connect(sender, signal, receiver, slot,
+ Qt::DirectConnection);
+ Q_ASSERT(connection);
+ QObject::connect(sender, signal, receiver,
+ [connection] { QObject::disconnect(connection); },
+ Qt::DirectConnection);
+ return connection;
+ }
+
/** Enumeration with flags defining the network job running policy
* So far only background/foreground flags are available.
*