#pragma once #include #include // FOR OLD QT class QThreadCreateThread : public QThread { public: explicit QThreadCreateThread(std::future &&future) : m_future(std::move(future)) { // deleteLater connect(this, &QThread::finished, this, &QThread::deleteLater); } private: void run() override { m_future.get(); } std::future m_future; }; inline QThread *createThreadImpl(std::future &&future) { return new QThreadCreateThread(std::move(future)); } template QThread *createQThread(Function &&f, Args &&... args) { using DecayedFunction = typename std::decay::type; auto threadFunction = [f = static_cast(std::forward(f))](auto &&... largs) mutable -> void { (void) std::invoke(std::move(f), std::forward(largs)...); }; return createThreadImpl(std::async(std::launch::deferred, std::move(threadFunction), std::forward(args)...)); }