blob: 9657c104271c16a71433e68ea90140763024074c (
plain)
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
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QProcess>
#include <QTextStream>
#include <unistd.h>
#include "processhandler.h"
ProcessHandler::ProcessHandler(QObject *parent, const QString &procPath, quint32 msec) :
QObject(parent),
m_process(new QProcess(this)),
m_procPath(procPath),
m_msec(msec)
{
m_process->setProgram(m_procPath);
QObject::connect(m_process, &QProcess::started, this, &ProcessHandler::procStarted);
}
ProcessHandler::~ProcessHandler()
{
this->closeProcess();
}
qint64 ProcessHandler::getProcId() const
{
return m_process->processId();
}
void ProcessHandler::closeProcess()
{
m_process->close();
}
void ProcessHandler::procStarted()
{
if (m_msec > 0) {
usleep(m_msec);
}
emit procReady();
}
void ProcessHandler::startProc()
{
m_process->start(m_procPath);
}
void ProcessHandler::startDetachedProc() const
{
m_process->startDetached(m_procPath);
}
QProcess* ProcessHandler::getPRocess() const {
return m_process;
}
|