-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWorkerBase.cpp
More file actions
61 lines (53 loc) · 969 Bytes
/
WorkerBase.cpp
File metadata and controls
61 lines (53 loc) · 969 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "WorkerBase.h"
#include "Exceptions.h"
#include "Log.h"
WorkerBase::WorkerBase(QString name)
: QObject(0)
, thread_(new QThread(0))
, error_message_()
{
setObjectName(name);
moveToThread(thread_);
connect(thread_, SIGNAL(started()), this, SLOT(processInternal()));
}
QString WorkerBase::errorMessage() const
{
return error_message_;
}
void WorkerBase::start()
{
thread_->start();
}
void WorkerBase::deleteLater()
{
QObject::deleteLater();
thread_->quit();
thread_->wait();
}
void WorkerBase::processInternal()
{
//start timer
QElapsedTimer timer;
timer.start();
//process
try
{
process();
}
catch (Exception& e)
{
error_message_ = "Error: " + e.message();
}
catch (std::exception& e)
{
error_message_ = "Error: " + QString::fromUtf8(e.what());
}
catch (...)
{
error_message_ = "Unknown error";
}
//emit finished signal
emit finished(error_message_=="");
//log time
Log::perf(objectName() + " took ", timer);
}