Workspace 6.21.5
Signals | Public Member Functions | List of all members
QProcessRobust Class Reference

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
 

Detailed Description

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.

Note
The function names used to get properties of the class differ from the usual convention used throughout the rest of the workspace code. This is to make the public interface of QProcessRobust be as close to QProcess as possible so that it can essentially be used as a drop-in replacement for the sort of scenarios QProcessRobust tries to address.

Constructor & Destructor Documentation

◆ QProcessRobust()

QProcessRobust ( QObject *  parent = nullptr)

◆ ~QProcessRobust()

~QProcessRobust ( )
override

Member Function Documentation

◆ environment()

QStringList environment ( ) const

Forwards to QProcess::environment()

◆ error()

QProcess::ProcessError error ( ) const
Returns
The last error recorded by the class. This is more or less the same as QProcess::error() but with some internal caching.

◆ errorString()

QString errorString ( ) const

Forwards to QProcess::errorString()

◆ exitCode()

int exitCode ( ) const

Forwards to QProcess::exitCode()

◆ exitStatus()

QProcess::ExitStatus exitStatus ( ) const

Forwards to QProcess::exitCode()

◆ kill()

void kill ( )

Forwards to QProcess::kill()

◆ processChannelMode()

QProcess::ProcessChannelMode processChannelMode ( ) const

Forwards to QProcess::processChannelMode()

◆ read() [1/2]

qint64 read ( char *  data,
qint64  maxSize 
)

Forwards to QProcess::read(char* data, qint64 maxSize)

◆ read() [2/2]

QByteArray read ( qint64  maxSize)

Forwards to QProcess::read(qint64 maxSize)

◆ readAll()

QByteArray readAll ( )

Forwards to QProcess::readAll()

◆ readAllStandardError()

QByteArray readAllStandardError ( )

Forwards to QProcess::readAllStandardError()

◆ readAllStandardOutput()

QByteArray readAllStandardOutput ( )

Forwards to QProcess::readAllStandardOutput()

◆ readLine() [1/2]

qint64 readLine ( char *  data,
qint64  maxSize 
)

Forwards to QProcess::readLine(char* data, qint64 maxSize)

◆ readLine() [2/2]

QByteArray readLine ( qint64  maxSize = 0)

Forwards to QProcess::readLine(qint64 maxSize)

◆ readyReadStandardError

void readyReadStandardError ( )
signal

◆ readyReadStandardOutput

void readyReadStandardOutput ( )
signal

◆ setEnvironment()

void setEnvironment ( const QStringList environment)

Forwards to QProcess::setEnvironment()

◆ setProcessChannelMode()

void setProcessChannelMode ( QProcess::ProcessChannelMode  mode)

Forwards to QProcess::setProcessChannelMode()

◆ setWorkingDirectory()

void setWorkingDirectory ( const QString &  dir)

Forwards to QProcess::setWorkingDirectory()

◆ start() [1/2]

void start ( const QString &  program,
const QStringList arguments,
QProcess::OpenMode  mode = QProcess::ReadWrite 
)
Parameters
programThe 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.
argumentsThe command-line arguments for program. If any contain spaces, they will be surrounded by quotes.
modeThe read/write mode of the started process. See the Qt documentation for QProcess for more details.

◆ start() [2/2]

void start ( const QString &  program,
QProcess::OpenMode  mode = QProcess::ReadWrite 
)
Parameters
programThe 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.
modeThe read/write mode of the started process. See the Qt documentation for QProcess for more details.

◆ terminate()

void terminate ( )

Forwards to QProcess::terminate()

◆ waitForFinished()

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).

Returns
True if the process finished successfully.

◆ waitForStarted()

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.

Returns
True if the process started successfully. If the process has already finished, this function still returns the state of the startup phase. If the startup phase was successful but the process experienced an error which caused it to terminate abnormally, waitForStarted() will still return true. This is to allow client code to distinguish where a process failure actually occurred.

◆ workingDirectory()

QString workingDirectory ( ) const

Forwards to QProcess::workingDirectory()