-
Notifications
You must be signed in to change notification settings - Fork 1
/
qJob.cpp
52 lines (43 loc) · 1.51 KB
/
qJob.cpp
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
// Qt includes
#include <QDebug>
#include <QFile>
// qJob includes
#include "qJob.h"
//-----------------------------------------------------------------------------
qJob::qJob(const QString& path, QObject *parent):Superclass(parent), Path(path)
{
qRegisterMetaType<QProcess::ExitStatus>();
}
//-----------------------------------------------------------------------------
qJob::~qJob()
{
}
//-----------------------------------------------------------------------------
void qJob::applicationStarted()
{
qDebug() << "Thread" << this->currentThreadId() << "process started";
}
//-----------------------------------------------------------------------------
void qJob::applicationFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitStatus);
qDebug() << "Thread" << this->currentThreadId()
<< "process finished with exitCode" << exitCode;
}
//-----------------------------------------------------------------------------
void qJob::run()
{
if (!QFile::exists(this->Path))
{
qCritical() << "Failed to start job" << this->currentThreadId()
<< " - JobPath set to a nonexistent file:" << this->Path;
return;
}
this->Process = new QProcess();
connect(this->Process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(applicationFinished(int, QProcess::ExitStatus)));
connect(this->Process, SIGNAL(started()), this, SLOT(applicationStarted()));
this->Process->start(this->Path);
qDebug() << "Starting thread" << this->currentThreadId();
exec();
}