-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathptyprocess.h
More file actions
54 lines (46 loc) · 1.11 KB
/
ptyprocess.h
File metadata and controls
54 lines (46 loc) · 1.11 KB
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
#pragma once
#include <QObject>
#include <QByteArray>
#include <QStringList>
#include <QProcess>
class QSocketNotifier;
class PtyProcess : public QObject
{
Q_OBJECT
public:
explicit PtyProcess(QObject *parent = nullptr) :
QObject(parent)
{}
~PtyProcess() override;
bool start(const QString &program, const QStringList &arguments);
qint64 write(const QByteArray &data);
pid_t pid() const { return _pid; }
void closeWriteChannel() { }
bool waitForFinished(int msecs = 30000);
QProcess::ProcessState state() const { return _state; }
QByteArray readAll()
{
QByteArray result;
result.swap(_buffer);
return result;
}
signals:
void readyRead();
void finished(int exitCode);
private slots:
void readAvailable()
{
readFromPty();
checkFinished();
}
private:
void readFromPty();
bool checkFinished();
void finishProcess(int exitCode);
private:
pid_t _pid {-1};
int _fd {-1};
QSocketNotifier *_notifier {nullptr};
QByteArray _buffer;
QProcess::ProcessState _state {QProcess::NotRunning};
};