-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWorkerBase.h
More file actions
40 lines (32 loc) · 1022 Bytes
/
WorkerBase.h
File metadata and controls
40 lines (32 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef WORKERBASE_H
#define WORKERBASE_H
#include "cppCORE_global.h"
#include <QObject>
#include <QThread>
///Base class for workers that do calculations in a background thread.
class CPPCORESHARED_EXPORT WorkerBase
: public QObject
{
Q_OBJECT
public:
///Constructor. The name is used for logging the processing time.
WorkerBase(QString name);
///Processing function that has to be implemented in derived classes. Set the error_message_ string in this method to make the processing as unsuccessful.
virtual void process() = 0;
///Returns the processing error message, or an empty string if the processing was successful.
QString errorMessage() const;
signals:
///Signal that is emitted when the processing is finished.
void finished(bool successful);
public slots:
///Starts the processing.
void start();
///Deletes this object and the background thread.
void deleteLater();
protected slots:
void processInternal();
protected:
QThread* thread_;
QString error_message_;
};
#endif // WORKERBASE_H