-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher.cpp
68 lines (59 loc) · 1.54 KB
/
launcher.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "launcher.h"
Launcher::Launcher(QObject *parent) :
QObject(parent),
m_process(new QProcess(this))
{
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SIGNAL(complete(int, QProcess::ExitStatus)));
}
Q_PID Launcher::start(const QString &program)
{
m_process->start(program);
return m_process->pid();
}
void Launcher::kill(void)
{
if (m_process->state() != QProcess::NotRunning) {
m_process->kill();
}
}
QString Launcher::readAll(void)
{
QString output = NULL;
if (m_process->state() == QProcess::NotRunning) {
QByteArray bytes = m_process->readAllStandardOutput();
output = QString::fromLocal8Bit(bytes);
}
return output;
}
void Launcher::wait(void)
{
if (m_process->state() != QProcess::NotRunning) {
m_process->waitForFinished(-1);
}
return;
}
void Launcher::start_wait(const QString &program)
{
// We want the finished() signal to be emitted only during
// asynchronous launch
m_process->blockSignals(true);
m_process->start(program);
m_process->waitForFinished(-1);
m_process->blockSignals(false);
}
QString Launcher::start_readAll(const QString &program)
{
// We want the finished() signal to be emitted only during
// asynchronous launch
m_process->blockSignals(true);
m_process->start(program);
m_process->waitForFinished(-1);
QByteArray bytes = m_process->readAllStandardOutput();
QString output = QString::fromLocal8Bit(bytes);
m_process->blockSignals(false);
return output;
}
Launcher::~Launcher()
{
}