Workspace 6.21.5
|
Safer implementation of a subset of what QProcess tries to achieve. More...
#include <Workspace/Application/System/qprocessrobust.h>
Inherits QObject.
Signals | |
void | readyReadStandardError () |
void | readyReadStandardOutput () |
Public Member Functions | |
QProcessRobust (QObject *parent=nullptr) | |
~QProcessRobust () override | |
QStringList | environment () const |
QProcess::ProcessError | error () const |
QString | errorString () const |
int | exitCode () const |
QProcess::ExitStatus | exitStatus () const |
void | kill () |
QProcess::ProcessChannelMode | processChannelMode () const |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
QByteArray | readAllStandardError () |
QByteArray | readAllStandardOutput () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize=0) |
void | setEnvironment (const QStringList &environment) |
void | setProcessChannelMode (QProcess::ProcessChannelMode mode) |
void | setWorkingDirectory (const QString &dir) |
void | start (const QString &program, const QStringList &arguments, QProcess::OpenMode mode=QProcess::ReadWrite) |
void | start (const QString &program, QProcess::OpenMode mode=QProcess::ReadWrite) |
void | terminate () |
bool | waitForFinished (int msecs=30000) |
bool | waitForStarted (int msecs=30000) |
QString | workingDirectory () const |
The way QProcess is implemented as of Qt 4.5, it is possible to miss signals indicating that a process has started or finished. The result is that applications can sometimes appear to hang while waiting for a process to start or finish when in fact the driving application simply missed the event occurring. The QProcessRobust class implements its public interface in such a way that it cannot miss a process starting or finishing. It is implemented in terms of QProcess but it sets up some additional signal-slot connections to ensure the state of the child process is properly monitored. It also tries to give a process time to finish before destroying itself in order to prevent warnings from Qt about deleting a running QProcess. This last scenario is sometimes encountered if client code is not careful about ensuring that waitForFinished() has been called for all exit paths from a function, for example.
QProcessRobust only attempts to implement the blocking interface to QProcess. This is the part of the current QProcess implementation which potentially misses signals. If you want to use the asynchronous interface to QProcess, you do not need to use QProcessRobust and indeed cannot fully because QProcessRobust is not a subclass of QIODevice, whereas QProcess is.
QProcessRobust | ( | QObject * | parent = nullptr | ) |
|
override |
QStringList environment | ( | ) | const |
Forwards to QProcess::environment()
QProcess::ProcessError error | ( | ) | const |
QProcess::error()
but with some internal caching. QString errorString | ( | ) | const |
Forwards to QProcess::errorString()
int exitCode | ( | ) | const |
Forwards to QProcess::exitCode()
QProcess::ExitStatus exitStatus | ( | ) | const |
Forwards to QProcess::exitCode()
void kill | ( | ) |
Forwards to QProcess::kill()
QProcess::ProcessChannelMode processChannelMode | ( | ) | const |
Forwards to QProcess::processChannelMode()
qint64 read | ( | char * | data, |
qint64 | maxSize | ||
) |
Forwards to QProcess::read(char* data, qint64 maxSize)
QByteArray read | ( | qint64 | maxSize | ) |
Forwards to QProcess::read(qint64 maxSize)
QByteArray readAll | ( | ) |
Forwards to QProcess::readAll()
QByteArray readAllStandardError | ( | ) |
Forwards to QProcess::readAllStandardError()
QByteArray readAllStandardOutput | ( | ) |
Forwards to QProcess::readAllStandardOutput()
qint64 readLine | ( | char * | data, |
qint64 | maxSize | ||
) |
Forwards to QProcess::readLine(char* data, qint64 maxSize)
QByteArray readLine | ( | qint64 | maxSize = 0 | ) |
Forwards to QProcess::readLine(qint64 maxSize)
|
signal |
|
signal |
void setEnvironment | ( | const QStringList & | environment | ) |
Forwards to QProcess::setEnvironment()
void setProcessChannelMode | ( | QProcess::ProcessChannelMode | mode | ) |
Forwards to QProcess::setProcessChannelMode()
void setWorkingDirectory | ( | const QString & | dir | ) |
Forwards to QProcess::setWorkingDirectory()
void start | ( | const QString & | program, |
const QStringList & | arguments, | ||
QProcess::OpenMode | mode = QProcess::ReadWrite |
||
) |
program | The executable to run. It must be either a full absolute path or it must refer to an executable that can be found on the current PATH by the system. It must not contain any command-line arguments. |
arguments | The command-line arguments for program. If any contain spaces, they will be surrounded by quotes. |
mode | The read/write mode of the started process. See the Qt documentation for QProcess for more details. |
void start | ( | const QString & | program, |
QProcess::OpenMode | mode = QProcess::ReadWrite |
||
) |
program | The command line to run. It must begin with either a full absolute path or a path to an executable that can be found on the current PATH by the system. The rest of the command line is interpretted as arguments to the command. |
mode | The read/write mode of the started process. See the Qt documentation for QProcess for more details. |
void terminate | ( | ) |
Forwards to QProcess::terminate()
bool waitForFinished | ( | int | msecs = 30000 | ) |
Unlike QProcess::waitForFinished(), this function can safely be called at any time after start(), although it would normally only be called after waitForStarted(). It will block for up to msecs milliseconds or until it can be confirmed that the child process has either finished or failed to start (this latter case is why clients should generally call waitForStarted() first).
bool waitForStarted | ( | int | msecs = 30000 | ) |
Unlike QProcess::waitForStarted(), this function can safely be called at any time after start(). It will block for up to msecs milliseconds or until it can be confirmed that the child process has either started or failed to start. The process can even have already finished.
QString workingDirectory | ( | ) | const |
Forwards to QProcess::workingDirectory()