aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-27 14:32:52 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-27 14:33:17 +0900
commit284b751ee424985341812a32721227112160a905 (patch)
treedd4617783038bc9063fd0caba840a936e84ad153 /lib/connection.h
parentd532b3f532c2daf45f6a03a7b48e923b6b7651ee (diff)
downloadlibquotient-284b751ee424985341812a32721227112160a905.tar.gz
libquotient-284b751ee424985341812a32721227112160a905.zip
connectSingleShot()
Time and again I need one-off slots that disconnect once they are done. The code has been inside Connection implementation for quite some time, now it's put to the interface for usage in other places (notably qmc-example).
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.
*