33 #ifndef CXTHREADEDTIMEDALGORITHM_H_
34 #define CXTHREADEDTIMEDALGORITHM_H_
36 #include "cxResourceExport.h"
38 #include <QFutureWatcher>
39 #include <QtConcurrent/QtConcurrentRun>
64 connect(&mWatcher, SIGNAL(finished()),
this, SLOT(finishedSlot()));
65 connect(&mWatcher, SIGNAL(finished()),
this, SLOT(postProcessingSlot()));
66 connect(&mWatcher, SIGNAL(finished()),
this, SIGNAL(finished()));
73 this->preProcessingSlot();
76 virtual bool isFinished()
const {
return mWatcher.isFinished(); }
77 virtual bool isRunning()
const {
return mWatcher.isRunning(); }
82 virtual void postProcessingSlot() = 0;
85 virtual T calculate() = 0;
93 mWatcher.setFuture(mFutureResult);
97 T result = mWatcher.future().result();
107 QFuture<T> mFutureResult;
108 QFutureWatcher<T> mWatcher;
131 virtual void postProcessingSlot();
134 virtual QString calculate();
ThreadedTimedAlgorithm(QString product, int secondsBetweenAnnounce)
Base class for algorithms that wants to time their execution.
Base class for algorithms that wants to thread and time their execution. T is the return type of the ...
virtual void preProcessingSlot()
This happens before the thread (calculate) is started, here non-thread safe functions can be called...
Implementation of ThreadedTimedAlgorithm that shows the minimum implementation of this class...
virtual ~ThreadedTimedAlgorithm()
virtual bool isFinished() const
virtual bool isRunning() const