6 #ifndef SWIFT_MISC_EVENTLOOP_H
7 #define SWIFT_MISC_EVENTLOOP_H
29 QObject::connect(guard, &QObject::destroyed, &m_eventLoop, [
this] { m_eventLoop.exit(TimedOut); });
33 template <
typename T,
typename F>
36 QObject::connect(sender, signal, &m_eventLoop, [
this] { m_eventLoop.exit(GotSignal); });
40 template <
typename T,
typename F1,
typename F2>
41 void stopWhen(
const T *sender, F1 signal, F2 &&condition)
43 QObject::connect(sender, signal, &m_eventLoop,
44 [
this, condition = std::forward<F2>(condition)](
auto &&...args) {
45 if (condition(std::forward<decltype(args)>(args)...)) { m_eventLoop.exit(GotSignal); }
57 return m_eventLoop.exec() == GotSignal &&
isGuardAlive();
69 QEventLoop m_eventLoop;
70 QPointer<QObject> m_guard;
Utility class which blocks until a signal is emitted or timeout reached.
CEventLoop(QObject *guard)
Constructor. Guard object must exist, and will be checked again when the loop quits.
bool exec(int timeoutMs)
Begin processing events until the timeout or stop condition occurs.
bool isGuardAlive() const
True if the guard object still exists.
void stopWhen(const T *sender, F1 signal, F2 &&condition)
Event loop will stop if the given signal is received and condition returns true.
void stopWhen(const T *sender, F signal)
Event loop will stop if the given signal is received.
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...