Learn Environment
process_runner.hpp
Go to the documentation of this file.
1 #ifndef PROCESS_RUNNER_HPP
2 #define PROCESS_RUNNER_HPP
3 
4 #include <QObject>
5 #include <QProcess>
6 #include <QTimer>
7 
15 class ProcessRunner : public QObject {
16  Q_OBJECT
17 
18 public:
27  ProcessRunner(const QString &program,
28  const QStringList &arguments,
29  int timeoutSeconds,
30  QObject *parent = nullptr,
31  QString processName = "process");
32 
36  void start();
37 
38 Q_SIGNALS:
44  void finished(int exitCode, QProcess::ExitStatus exitStatus);
45 
50  void outputReady(const QString &output);
51 
56  void errorReady(const QString &error);
57 
61  void timeout();
62 
63 public Q_SLOTS:
67  void forceStop();
68 
69 private Q_SLOTS:
75  void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
76 
80  void onReadyReadStandardOutput();
81 
85  void onReadyReadStandardError();
86 
90  void onTimeout();
91 
92 private:
93  QProcess *process;
94  QTimer *timer;
95  QString program;
96  QStringList arguments;
97  int timeoutSeconds;
98  QString processName;
99 };
100 
101 #endif // PROCESS_RUNNER_HPP
ProcessRunner::forceStop
void forceStop()
Forces the stop of the running process.
Definition: process_runner.cpp:35
QObject
ProcessRunner::errorReady
void errorReady(const QString &error)
Signal emitted when the process produces an error.
ProcessRunner::start
void start()
Starts the execution of the process.
Definition: process_runner.cpp:25
ProcessRunner
Manages the execution of an external process with a timeout.
Definition: process_runner.hpp:15
ProcessRunner::outputReady
void outputReady(const QString &output)
Signal emitted when the process produces output.
process_runner.hpp
ProcessRunner::ProcessRunner
ProcessRunner(const QString &program, const QStringList &arguments, int timeoutSeconds, QObject *parent=nullptr, QString processName="process")
Constructs a ProcessRunner object.
Definition: process_runner.cpp:10
ProcessRunner::finished
void finished(int exitCode, QProcess::ExitStatus exitStatus)
Signal emitted when the process finishes.
ProcessRunner::timeout
void timeout()
Signal emitted when the process times out.