diff --git a/src/public/async.cpp b/src/public/async.cpp index ba864c5..a914b3b 100644 --- a/src/public/async.cpp +++ b/src/public/async.cpp @@ -35,6 +35,7 @@ return CONDITION; \ namespace QH { + Async::Async(QThread *thread, QObject *ptr): QObject(ptr) { diff --git a/src/public/asynclauncher.cpp b/src/public/asynclauncher.cpp index fe83e55..39e53fe 100644 --- a/src/public/asynclauncher.cpp +++ b/src/public/asynclauncher.cpp @@ -6,6 +6,8 @@ */ #include "asynclauncher.h" + +#include namespace QH { AsyncLauncher::AsyncLauncher(QThread *thread, QObject *ptr): @@ -14,7 +16,27 @@ AsyncLauncher::AsyncLauncher(QThread *thread, QObject *ptr): bool AsyncLauncher::run(const Async::Job &action, bool wait) { + if (thread() && !thread()->isRunning()) { + thread()->start(); + } + return asyncLauncher(action, wait); } +bool AsyncLauncher::stop() { + if (thread() && thread()->isRunning()) { + thread()->exit(); + } + + return true; +} + +bool AsyncLauncher::waitForStop() { + if (thread() && thread()->isRunning()) { + return thread()->wait(); + } + + return true; +} + } diff --git a/src/public/asynclauncher.h b/src/public/asynclauncher.h index 6d1e819..525f95d 100644 --- a/src/public/asynclauncher.h +++ b/src/public/asynclauncher.h @@ -47,6 +47,18 @@ public: */ bool run(const Job &action, bool wait = false); + /** + * @brief stop This method stop the work thread of this object. + * @return true if the thread is stopped. + */ + bool stop(); + + /** + * @brief waitForStop This method wait for the thread of this object is stopped. + * @return true if the thread is stopped. + */ + bool waitForStop(); + }; } diff --git a/src/public/asyncrenderloop.h b/src/public/asyncrenderloop.h index f653c40..2cfc048 100644 --- a/src/public/asyncrenderloop.h +++ b/src/public/asyncrenderloop.h @@ -132,7 +132,7 @@ public: /** * @brief stop This method stops the render loop. */ - void stop(); + virtual void stop(); /** * @brief isRun This method returns the state of the render loop.