forked from linux4sam/application-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.cpp
107 lines (88 loc) · 2.18 KB
/
process.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (C) 2013-2015 Atmel Corporation.
*
* This file is licensed under the terms of the Atmel LIMITED License Agreement
* as written in the COPYING file that is delivered in the project root directory.
*
* DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
* See the COPYING license file for more details.
*/
#include "process.h"
#include <QtCore/QProcess>
#include <QDebug>
#include <QFileInfo>
#include <QDir>
class Process::Private : public QProcess
{
Q_OBJECT
public:
Private(Process *parent);
QString program;
QStringList arguments;
private:
Process *q;
};
Process::Private::Private(Process *parent)
: QProcess(parent)
, q(parent)
{
connect(this, SIGNAL(started()), q, SIGNAL(started()));
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), q, SIGNAL(finished(int)));
connect(this, SIGNAL(readyReadStandardOutput()), q, SIGNAL(readyReadStandardOutput()));
connect(this, SIGNAL(readyReadStandardError()), q, SIGNAL(readyReadStandardError()));
}
Process::Process(QObject *parent)
: QObject(parent)
, d(new Private(this))
{
}
Process::~Process()
{
}
const QString &Process::program() const
{
return d->program;
}
void Process::setProgram(const QString &program)
{
if (program == d->program) return;
d->program = program;
emit programChanged(d->program);
}
const QStringList &Process::arguments() const
{
return d->arguments;
}
void Process::setArguments(const QStringList &arguments)
{
if (arguments == d->arguments) return;
d->arguments = arguments;
emit argumentsChanged(d->arguments);
}
void Process::start()
{
d->startDetached(d->program, d->arguments);
bool result = d->waitForStarted(7000);
// next lines just for control if there any error
qDebug() << "\t### STARTED: " << result;
if (!result) {
qDebug() << "QProcess::ProcessError: " << d->error();
}
}
void Process::terminate()
{
d->terminate();
}
void Process::kill()
{
d->kill();
}
QByteArray Process::readAllStandardError()
{
return d->readAllStandardError();
}
QByteArray Process::readAllStandardOutput()
{
return d->readAllStandardOutput();
}
#include "process.moc"