-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunexternalprocess.cpp
executable file
·52 lines (47 loc) · 1.83 KB
/
runexternalprocess.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
#include "runexternalprocess.h"
#include "ui_runexternalprocess.h"
#include <QProcess>
#include <QStringList>
QProcess *process;
QString gcommand;
QStringList gargs;
RunExternalProcess::RunExternalProcess(const QString& command, const QStringList& args, const QString& workingDirectory, QWidget *parent) :
QDialog(parent),
ui(new Ui::RunExternalProcess)
{
ui->setupUi(this);
gcommand = command;
gargs = args;
setWindowTitle(tr("Running") + " " + command);
process = new QProcess;
process->setProcessChannelMode(QProcess::MergedChannels);
if (!workingDirectory.isEmpty())
process->setWorkingDirectory(workingDirectory);
connect(process, &QProcess::readyReadStandardOutput,
[=](){ ui->plainTextEdit->appendPlainText(QString(process->readAllStandardOutput())); });
}
RunExternalProcess::~RunExternalProcess() {
process->terminate();
if (!process->waitForFinished(10000))
process->kill();
delete ui;
}
void RunExternalProcess::nonDialogMode(const QString& command, const QStringList& args, const QString& workingDirectory) {
process = new QProcess;
process->setProcessChannelMode(QProcess::MergedChannels);
if (!workingDirectory.isEmpty())
process->setWorkingDirectory(workingDirectory);
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [=](){
process->terminate();
if (!process->waitForFinished(10000))
process->kill();
});
process->start(command, args);
}
int RunExternalProcess::exec() {
ui->buttonBox->setEnabled(false);
process->start(gcommand, gargs);
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
[=](int, QProcess::ExitStatus){ ui->buttonBox->setEnabled(true); });
return QDialog::exec();
}