Learn Environment
Loading...
Searching...
No Matches
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
15class ProcessRunner : public QObject {
16 Q_OBJECT
17
18public:
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
38Q_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
63public Q_SLOTS:
67 void forceStop();
68
69private Q_SLOTS:
75 void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
76
80 void onReadyReadStandardOutput();
81
85 void onReadyReadStandardError();
86
90 void onTimeout();
91
92private:
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
Manages the execution of an external process with a timeout.
Definition process_runner.hpp:15
void finished(int exitCode, QProcess::ExitStatus exitStatus)
Signal emitted when the process finishes.
ProcessRunner(const QString &program, const QStringList &arguments, int timeoutSeconds, QObject *parent=nullptr, QString processName="process")
Constructs a ProcessRunner object.
Definition process_runner.cpp:10
void errorReady(const QString &error)
Signal emitted when the process produces an error.
void forceStop()
Forces the stop of the running process.
Definition process_runner.cpp:35
void outputReady(const QString &output)
Signal emitted when the process produces output.
void timeout()
Signal emitted when the process times out.
void start()
Starts the execution of the process.
Definition process_runner.cpp:25