6 #ifndef SWIFT_MISC_THREADUTILS_H
7 #define SWIFT_MISC_THREADUTILS_H
11 #include <QMetaObject>
13 #include <QSharedPointer>
33 QSharedPointer<QTimer> timer(
new QTimer,
34 [](QObject *o) { QMetaObject::invokeMethod(o, &QObject::deleteLater); });
35 timer->setSingleShot(
true);
36 timer->moveToThread(target->thread());
37 QObject::connect(timer.data(), &QTimer::timeout, target,
38 [trace =
getStackTrace(), task = std::forward<F>(task), timer, promise]()
mutable {
39 static_cast<void>(trace);
43 QMetaObject::invokeMethod(timer.data(), [t = timer.data(), msec] { t->start(msec); });
59 static bool isInThisThread(
const QObject *toBeTested);
64 static bool thisIsMainThread();
67 static QString currentThreadInfo();
A promise-based interface to QFuture, similar to std::promise for std::future.
QFuture< T > future()
Return a future that can be used to access the result.
void setResultFrom(F &&func)
Invoke a functor and use its return value to set the result.
Utility class for threaded operations.
CThreadUtils()=delete
No constructor.
Free functions in swift::misc.
QStringList getStackTrace()
Returns a stack trace of the current thread of execution as a list of function names.
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...
#define SWIFT_MISC_EXPORT
Export a class or function from the library.