QProcess Class Reference

The QProcess class is used to start external programs and to communicate with them.

  1. #include <QProcess>

Inherits: QIODevice.

Note: All functions in this class are reentrant.

Detailed Description

The QProcess class is used to start external programs and to communicate with them.

Running a Process

To start a process, pass the name and command line arguments of the program you want to run as arguments to start(). Arguments are supplied as individual strings in a QStringList.

For example, the following code snippet runs the analog clock example in the Motif style on X11 platforms by passing strings containing "-style" and "motif" as two items in the list of arguments:

  1.     QObject *parent;
  2.     ...
  3.     QString program = "./path/to/Qt/examples/widgets/analogclock";
  4.     QStringList arguments;
  5.     arguments << "-style" << "motif";
  6.  
  7.     QProcess *myProcess = new QProcess(parent);
  8.     myProcess->start(program, arguments);

QProcess then enters the Starting state, and when the program has started, QProcess enters the Running state and emits started().

QProcess allows you to treat a process as a sequential I/O device. You can write to and read from the process just as you would access a network connection using QTcpSocket. You can then write to the process's standard input by calling write(), and read the standard output by calling read(), readLine(), and getChar(). Because it inherits QIODevice, QProcess can also be used as an input source for QXmlReader, or for generating data to be uploaded using QFtp.

Note: On Windows CE and Symbian, reading and writing to a process is not supported.

When the process exits, QProcess reenters the NotRunning state (the initial state), and emits finished().

The finished() signal provides the exit code and exit status of the process as arguments, and you can also call exitCode() to obtain the exit code of the last process that finished, and exitStatus() to obtain its exit status. If an error occurs at any point in time, QProcess will emit the error() signal. You can also call error() to find the type of error that occurred last, and state() to find the current process state.

Communicating via Channels

Processes have two predefined output channels: The standard output channel (stdout) supplies regular console output, and the standard error channel (stderr) usually supplies the errors that are printed by the process. These channels represent two separate streams of data. You can toggle between them by calling setReadChannel(). QProcess emits readyRead() when data is available on the current read channel. It also emits readyReadStandardOutput() when new standard output data is available, and when new standard error data is available, readyReadStandardError() is emitted. Instead of calling read(), readLine(), or getChar(), you can explicitly read all data from either of the two channels by calling readAllStandardOutput() or readAllStandardError().

The terminology for the channels can be misleading. Be aware that the process's output channels correspond to QProcess's read channels, whereas the process's input channels correspond to QProcess's write channels. This is because what we read using QProcess is the process's output, and what we write becomes the process's input.

QProcess can merge the two output channels, so that standard output and standard error data from the running process both use the standard output channel. Call setProcessChannelMode() with MergedChannels before starting the process to activative this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing ForwardedChannels as the argument.

Certain processes need special environment settings in order to operate. You can set environment variables for your process by calling setEnvironment(). To set a working directory, call setWorkingDirectory(). By default, processes are run in the current working directory of the calling process.

Note: On Symbian, setting environment or working directory is not supported. The working directory will always be the private directory of the running process.

Synchronous Process API

QProcess provides a set of functions which allow it to be used without an event loop, by suspending the calling thread until certain signals are emitted:

Calling these functions from the main thread (the thread that calls QApplication::exec()) may cause your user interface to freeze.

The following example runs gzip to compress the string "Qt rocks!", without an event loop:

  1.     QProcess gzip;
  2.     gzip.start("gzip", QStringList() << "-c");
  3.     if (!gzip.waitForStarted())
  4.         return false;
  5.  
  6.     gzip.write("Qt rocks!");
  7.     gzip.closeWriteChannel();
  8.  
  9.     if (!gzip.waitForFinished())
  10.         return false;
  11.  
  12.     QByteArray result = gzip.readAll();

Notes for Windows Users

Some Windows commands (for example, dir) are not provided by separate applications, but by the command interpreter itself. If you attempt to use QProcess to execute these commands directly, it won't work. One possible solution is to execute the command interpreter itself (cmd.exe on some Windows systems), and ask the interpreter to execute the desired command.

Symbian Platform Security Requirements

On Symbian, processes which use the functions kill() or terminate() must have the PowerMgmt platform security capability. If the client process lacks this capability, these functions will fail.

Platform security capabilities are added via the TARGET.CAPABILITY qmake variable.

See also QBuffer, QFile, and QTcpSocket.

Public Types

Toggle detailsenum QProcess::

ExitStatusExitStatus { NormalExit , CrashExit 1 ...} { NormalExit , CrashExit 1 }

This enum describes the different exit statuses of QProcess.

ConstantValueDescription
QProcess::NormalExit 0 The process exited normally.
QProcess::CrashExit 1 The process crashed.

See also exitStatus().

Look up this member in the source code.

Toggle detailsenum QProcess::

ProcessChannelProcessChannel { StandardOutput , StandardError 1 ...} { StandardOutput , StandardError 1 }

This enum describes the process channels used by the running process. Pass one of these values to setReadChannel() to set the current read channel of QProcess.

ConstantValueDescription
QProcess::StandardOutput 0 The standard output (stdout) of the running process.
QProcess::StandardError 1 The standard error (stderr) of the running process.

See also setReadChannel().

Look up this member in the source code.

Toggle detailsenum QProcess::

ProcessChannelModeProcessChannelMode { SeparateChannels , MergedChannels , ForwardedChannels 2 ...} { SeparateChannels , MergedChannels , ForwardedChannels 2 }

This enum describes the process channel modes of QProcess. Pass one of these values to setProcessChannelMode() to set the current read channel mode.

ConstantValueDescription
QProcess::SeparateChannels 0 QProcess manages the output of the running process, keeping standard output and standard error data in separate internal buffers. You can select the QProcess's current read channel by calling setReadChannel(). This is the default channel mode of QProcess.
QProcess::MergedChannels 1 QProcess merges the output of the running process into the standard output channel (stdout). The standard error channel (stderr) will not receive any data. The standard output and standard error data of the running process are interleaved.
QProcess::ForwardedChannels 2 QProcess forwards the output of the running process onto the main process. Anything the child process writes to its standard output and standard error will be written to the standard output and standard error of the main process.

See also setProcessChannelMode().

Look up this member in the source code.

Toggle detailsenum QProcess::

ProcessErrorProcessError { FailedToStart , Crashed , Timedout , ReadError , WriteError , UnknownError 5 ...} { FailedToStart , Crashed , Timedout , ReadError , WriteError , UnknownError 5 }

This enum describes the different types of errors that are reported by QProcess.

ConstantValueDescription
QProcess::FailedToStart 0 The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
QProcess::Crashed 1 The process crashed some time after starting successfully.
QProcess::Timedout 2 The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.
QProcess::WriteError 4 An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
QProcess::ReadError 3 An error occurred when attempting to read from the process. For example, the process may not be running.
QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().

See also error().

Look up this member in the source code.

Toggle detailsenum QProcess::

ProcessStateProcessState { NotRunning , Starting , Running 2 ...} { NotRunning , Starting , Running 2 }

This enum describes the different states of QProcess.

ConstantValueDescription
QProcess::NotRunning 0 The process is not running.
QProcess::Starting 1 The process is starting, but the program has not yet been invoked.
QProcess::Running 2 The process is running and is ready for reading and writing.

See also state().

Look up this member in the source code.

    Public Functions

    Toggle details QProcess

    QProcessQProcess ( QObject *parent=0 ) ( QObject *parent=0 )

    Constructs a QProcess object with the given parent.

    Look up this member in the source code.

    Toggle details QProcess

    ~QProcess~QProcess () () [virtual]

    Destructs the QProcess object, i.e., killing the process.

    Note that this function will not return until the process is terminated.

    Look up this member in the source code.

    Toggle details bool QProcess

    atEndatEnd () ()const [virtual]

    Reimplemented from QIODevice::atEnd().

    Returns true if the process is not running, and no more data is available for reading; otherwise returns false.

    Look up this member in the source code.

    Toggle details qint64 QProcess

    bytesAvailablebytesAvailable () ()const [virtual]

    Reimplemented from QIODevice::bytesAvailable().

    Look up this member in the source code.

    Toggle details qint64 QProcess

    bytesToWritebytesToWrite () ()const [virtual]

    Reimplemented from QIODevice::bytesToWrite().

    Look up this member in the source code.

    Toggle details bool QProcess

    canReadLinecanReadLine () ()const [virtual]

    Reimplemented from QIODevice::canReadLine().

    This function operates on the current read channel.

    See also readChannel() and setReadChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    closeclose () () [virtual]

    Reimplemented from QIODevice::close().

    Closes all communication with the process and kills it. After calling this function, QProcess will no longer emit readyRead(), and data can no longer be read or written.

    Look up this member in the source code.

    Toggle details void QProcess

    closeReadChannelcloseReadChannel ( ProcessChannel channel ) ( ProcessChannel channel )

    Closes the read channel channel. After calling this function, QProcess will no longer receive data on the channel. Any data that has already been received is still available for reading.

    Call this function to save memory, if you are not interested in the output of the process.

    See also closeWriteChannel() and setReadChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    closeWriteChannelcloseWriteChannel () ()

    Schedules the write channel of QProcess to be closed. The channel will close once all data has been written to the process. After calling this function, any attempts to write to the process will fail.

    Closing the write channel is necessary for programs that read input data until the channel has been closed. For example, the program "more" is used to display text data in a console on both Unix and Windows. But it will not display the text data until QProcess's write channel has been closed. Example:

    1.                     QProcess more;
    2. more.start("more");
    3. more.write("Text to display");
    4. more.closeWriteChannel();
    5. // QProcess will emit readyRead() once "more" starts printing

    The write channel is implicitly opened when start() is called.

    See also closeReadChannel().

    Look up this member in the source code.

    Toggle details QStringList QProcess

    environmentenvironment () ()const

    Returns the environment that QProcess will use when starting a process, or an empty QStringList if no environment has been set using setEnvironment() or setEnvironmentHash(). If no environment has been set, the environment of the calling process will be used.

    Note: The environment settings are ignored on Windows CE and Symbian, as there is no concept of an environment.

    See also processEnvironment(), setEnvironment(), and systemEnvironment().

    Look up this member in the source code.

    Toggle details QProcess::ProcessError QProcess

    errorerror () ()const

    Returns the type of error that occurred last.

    See also state().

    Look up this member in the source code.

    Toggle details int QProcess

    executeexecute ( const QString &program , const QStringList &arguments ...) ( const QString &program , const QStringList &arguments ) [static]

    Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

    The environment and working directory are inherited from the calling process.

    On Windows, arguments that contain spaces are wrapped in quotes.

    If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.

    Look up this member in the source code.

    Toggle details int QProcess

    executeexecute ( const QString &program ) ( const QString &program ) [static]

    This is an overloaded function.

    Starts the program program in a new process. program is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.

    Look up this member in the source code.

    Toggle details int QProcess

    exitCodeexitCode () ()const

    Returns the exit code of the last process that finished.

    Look up this member in the source code.

    Toggle details QProcess::ExitStatus QProcess

    exitStatusexitStatus () ()const

    Returns the exit status of the last process that finished.

    On Windows, if the process was terminated with TerminateProcess() from another application this function will still return NormalExit unless the exit code is less than 0.

    Look up this member in the source code.

    Toggle details bool QProcess

    isSequentialisSequential () ()const [virtual]

    Reimplemented from QIODevice::isSequential().

    Look up this member in the source code.

    Toggle details QString QProcess

    nativeArgumentsnativeArguments () ()const

    Returns the additional native command line arguments for the program.

    Note: This function is available only on the Windows and Symbian platforms.

    See also setNativeArguments().

    Look up this member in the source code.

    Toggle details Q_PID QProcess

    pidpid () ()const

    Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned.

    Look up this member in the source code.

    Toggle details ProcessChannelMode QProcess

    processChannelModeprocessChannelMode () ()const

    Returns the channel mode of the QProcess standard output and standard error channels.

    See also setProcessChannelMode(), ProcessChannelMode, and setReadChannel().

    Look up this member in the source code.

    Toggle details QProcessEnvironment QProcess

    processEnvironmentprocessEnvironment () ()const

    Returns the environment that QProcess will use when starting a process, or an empty object if no environment has been set using setEnvironment() or setProcessEnvironment(). If no environment has been set, the environment of the calling process will be used.

    Note: The environment settings are ignored on Windows CE, as there is no concept of an environment.

    See also setProcessEnvironment(), setEnvironment(), and QProcessEnvironment::isEmpty().

    Look up this member in the source code.

    Toggle details QByteArray QProcess

    readAllStandardErrorreadAllStandardError () ()

    Regardless of the current read channel, this function returns all data available from the standard error of the process as a QByteArray.

    See also readyReadStandardError(), readAllStandardOutput(), readChannel(), and setReadChannel().

    Look up this member in the source code.

    Toggle details QByteArray QProcess

    readAllStandardOutputreadAllStandardOutput () ()

    Regardless of the current read channel, this function returns all data available from the standard output of the process as a QByteArray.

    See also readyReadStandardOutput(), readAllStandardError(), readChannel(), and setReadChannel().

    Look up this member in the source code.

    Toggle details ProcessChannel QProcess

    readChannelreadChannel () ()const

    Returns the current read channel of the QProcess.

    See also setReadChannel().

    Look up this member in the source code.

    Toggle details qint64 QProcess

    readDatareadData ( char *data , qint64 maxlen ) ( char *data , qint64 maxlen ) [virtual protected]

    Reimplemented from QIODevice::readData().

    Look up this member in the source code.

    Toggle details void QProcess

    setEnvironmentsetEnvironment ( const QStringList &environment ...) ( const QStringList &environment )

    Sets the environment that QProcess will use when starting a process to the environment specified which consists of a list of key=value pairs.

    For example, the following code adds the C:\\BIN directory to the list of executable paths (PATHS) on Windows:

    1.                     QProcess process;
    2. QStringList env = QProcess::systemEnvironment();
    3. env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
    4. env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin");
    5. process.setEnvironment(env);
    6. process.start("myapp");

    Note: This function is less efficient than the setProcessEnvironment() function.

    See also environment(), setProcessEnvironment(), and systemEnvironment().

    Look up this member in the source code.

    Toggle details void QProcess

    setNativeArgumentssetNativeArguments ( const QString &arguments ) ( const QString &arguments )

    This is an overloaded function.

    Sets additional native command line arguments for the program.

    On operating systems where the system API for passing command line arguments to a subprocess natively uses a single string, one can conceive command lines which cannot be passed via QProcess's portable list-based API. In such cases this function must be used to set a string which is appended to the string composed from the usual argument list, with a delimiting space.

    Note: This function is available only on the Windows and Symbian platforms.

    See also nativeArguments().

    Look up this member in the source code.

    Toggle details void QProcess

    setProcessChannelModesetProcessChannelMode ( ProcessChannelMode mode ...) ( ProcessChannelMode mode )

    Sets the channel mode of the QProcess standard output and standard error channels to the mode specified. This mode will be used the next time start() is called. For example:

    1.                     QProcess builder;
    2. builder.setProcessChannelMode(QProcess::MergedChannels);
    3. builder.start("make", QStringList() << "-j2");
    4.  
    5. if (!builder.waitForFinished())
    6.     qDebug() << "Make failed:" << builder.errorString();
    7. else
    8.     qDebug() << "Make output:" << builder.readAll();

    See also processChannelMode(), ProcessChannelMode, and setReadChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    setProcessEnvironmentsetProcessEnvironment ( const QProcessEnvironment &environment ...) ( const QProcessEnvironment &environment )

    Sets the environment that QProcess will use when starting a process to the environment object.

    For example, the following code adds the C:\\BIN directory to the list of executable paths (PATHS) on Windows and sets TMPDIR:

    1.                     QProcess process;
    2. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    3. env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
    4. env.insert("PATH", env.value("Path") + ";C:\\Bin");
    5. process.setProcessEnvironment(env);
    6. process.start("myapp");

    Note how, on Windows, environment variable names are case-insensitive.

    See also processEnvironment(), QProcessEnvironment::systemEnvironment(), and setEnvironment().

    Look up this member in the source code.

    Toggle details void QProcess

    setProcessStatesetProcessState ( ProcessState state ) ( ProcessState state )[protected]

    Sets the current state of the QProcess to the state specified.

    See also state().

    Look up this member in the source code.

    Toggle details void QProcess

    setReadChannelsetReadChannel ( ProcessChannel channel ) ( ProcessChannel channel )

    Sets the current read channel of the QProcess to the given channel. The current input channel is used by the functions read(), readAll(), readLine(), and getChar(). It also determines which channel triggers QProcess to emit readyRead().

    See also readChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    setStandardErrorFilesetStandardErrorFile ( const QString &fileName , OpenMode mode=Truncate ...) ( const QString &fileName , OpenMode mode=Truncate )

    Redirects the process' standard error to the file fileName. When the redirection is in place, the standard error read channel is closed: reading from it using read() will always fail, as will readAllStandardError(). The file will be appended to if mode is Append, otherwise, it will be truncated.

    See setStandardOutputFile() for more information on how the file is opened.

    Note: if setProcessChannelMode() was called with an argument of QProcess::MergedChannels, this function has no effect.

    See also setStandardInputFile(), setStandardOutputFile(), and setStandardOutputProcess().

    Look up this member in the source code.

    Toggle details void QProcess

    setStandardInputFilesetStandardInputFile ( const QString &fileName ( const QString &fileName )

    Redirects the process' standard input to the file indicated by fileName. When an input redirection is in place, the QProcess object will be in read-only mode (calling write() will result in error).

    If the file fileName does not exist at the moment start() is called or is not readable, starting the process will fail.

    Calling setStandardInputFile() after the process has started has no effect.

    See also setStandardOutputFile(), setStandardErrorFile(), and setStandardOutputProcess().

    Look up this member in the source code.

    Toggle details void QProcess

    setStandardOutputFilesetStandardOutputFile ( const QString &fileName , OpenMode mode=Truncate ...) ( const QString &fileName , OpenMode mode=Truncate )

    Redirects the process' standard output to the file fileName. When the redirection is in place, the standard output read channel is closed: reading from it using read() will always fail, as will readAllStandardOutput().

    If the file fileName doesn't exist at the moment start() is called, it will be created. If it cannot be created, the starting will fail.

    If the file exists and mode is QIODevice::Truncate, the file will be truncated. Otherwise (if mode is QIODevice::Append), the file will be appended to.

    Calling setStandardOutputFile() after the process has started has no effect.

    See also setStandardInputFile(), setStandardErrorFile(), and setStandardOutputProcess().

    Look up this member in the source code.

    Toggle details void QProcess

    setStandardOutputProcesssetStandardOutputProcess ( QProcess *destination ...) ( QProcess *destination )

    Pipes the standard output stream of this process to the destination process' standard input.

    The following shell command:

    1. command1 | command2

    Can be accomplished with QProcesses with the following code:

    1.                     QProcess process1;
    2. QProcess process2;
    3.  
    4. process1.setStandardOutputProcess(&process2);
    5.  
    6. process1.start("command1");
    7. process2.start("command2");

    Look up this member in the source code.

    Toggle details void QProcess

    setWorkingDirectorysetWorkingDirectory ( const QString &dir ) ( const QString &dir )

    Sets the working directory to dir. QProcess will start the process in this directory. The default behavior is to start the process in the working directory of the calling process.

    Note: The working directory setting is ignored on Symbian; the private directory of the process is considered its working directory.

    See also workingDirectory() and start().

    Look up this member in the source code.

    Toggle details void QProcess

    setupChildProcesssetupChildProcess () () [virtual protected]

    This function is called in the child process context just before the program is executed on Unix or Mac OS X (i.e., after fork(), but before execve()). Reimplement this function to do last minute initialization of the child process. Example:

    1. class SandboxProcess : public QProcess
    2.  {
    3.     ...
    4.  protected:
    5.      void setupChildProcess();
    6.     ...
    7. };
    8.  
    9. void SandboxProcess::setupChildProcess()
    10.  {
    11.     // Drop all privileges in the child process, and enter
    12.     // a chroot jail.
    13. #if defined Q_OS_UNIX
    14.     ::setgroups(0, 0);
    15.     ::chroot("/etc/safe");
    16.     ::chdir("/");
    17.     ::setgid(safeGid);
    18.     ::setuid(safeUid);
    19.     ::umask(0);
    20. #endif
    21. }

    You cannot exit the process (by calling exit(), for instance) from this function. If you need to stop the program before it starts execution, your workaround is to emit finished() and then call exit().

    Warning: This function is called by QProcess on Unix and Mac OS X only. On Windows, it is not called.

    Look up this member in the source code.

    Toggle details void QProcess

    startstart ( const QString &program , const QStringList &arguments , OpenMode mode=ReadWrite ...) ( const QString &program , const QStringList &arguments , OpenMode mode=ReadWrite )

    Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. The OpenMode is set to mode.

    The QProcess object will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, error() will be emitted. If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running.

    Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.

    Note: No further splitting of the arguments is performed.

    Windows: Arguments that contain spaces are wrapped in quotes.

    See also pid(), started(), and waitForStarted().

    Look up this member in the source code.

    Toggle details void QProcess

    startstart ( const QString &program , OpenMode mode=ReadWrite ...) ( const QString &program , OpenMode mode=ReadWrite )

    This is an overloaded function.

    Starts the program program in a new process, if one is not already running. program is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces. For example:

    1.                     QProcess process;
    2. process.start("del /s *.txt");
    3. // same as process.start("del", QStringList() << "/s" << "*.txt");
    4. ...

    The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example:

    1.                     QProcess process;
    2. process.start("dir \"My Documents\"");

    If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running.

    Note that, on Windows, quotes need to be both escaped and quoted. For example, the above code would be specified in the following way to ensure that "My Documents" is used as the argument to the dir executable:

    1.                     QProcess process;
    2. process.start("dir \"\"\"My Documents\"\"\"");

    The OpenMode is set to mode.

    Look up this member in the source code.

    Toggle details bool QProcess

    startDetachedstartDetached ( const QString &program , const QStringList &arguments , const QString &workingDirectory , qint64 *pid=0 ...) ( const QString &program , const QStringList &arguments , const QString &workingDirectory , qint64 *pid=0 ) [static]

    Starts the program program with the arguments arguments in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.

    Note that arguments that contain spaces are not passed to the process as separate arguments.

    Unix: The started process will run in its own session and act like a daemon.

    Windows: Arguments that contain spaces are wrapped in quotes. The started process will run as a regular standalone process.

    The process will be started in the directory workingDirectory.

    If the function is successful then *pid is set to the process identifier of the started process.

    Look up this member in the source code.

    Toggle details bool QProcess

    startDetachedstartDetached ( const QString &program , const QStringList &arguments ...) ( const QString &program , const QStringList &arguments ) [static]

    Starts the program program with the given arguments in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.

    Note: Arguments that contain spaces are not passed to the process as separate arguments.

    Unix: The started process will run in its own session and act like a daemon.

    Windows: Arguments that contain spaces are wrapped in quotes. The started process will run as a regular standalone process.

    Look up this member in the source code.

    Toggle details bool QProcess

    startDetachedstartDetached ( const QString &program ) ( const QString &program ) [static]

    This is an overloaded function.

    Starts the program program in a new process. program is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.

    The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process.

    Look up this member in the source code.

    Toggle details QProcess::ProcessState QProcess

    statestate () ()const

    Returns the current state of the process.

    See also stateChanged() and error().

    Look up this member in the source code.

    Toggle details QStringList QProcess

    systemEnvironmentsystemEnvironment () () [static]

    Returns the environment of the calling process as a list of key=value pairs. Example:

    1.                     QStringList environment = QProcess::systemEnvironment();
    2. // environment =  {"PATH=/usr/bin:/usr/local/bin",
    3. //                "USER=greg", "HOME=/home/greg"}

    This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C library functions like setenv ot putenv have been called.

    However, note that repeated calls to this function will recreate the list of environment variables, which is a non-trivial operation.

    Note: For new code, it is recommended to use QProcessEvironment::systemEnvironment()

    See also QProcessEnvironment::systemEnvironment(), environment(), and setEnvironment().

    Look up this member in the source code.

    Toggle details bool QProcess

    waitForBytesWrittenwaitForBytesWritten ( int msecs=30000 ) ( int msecs=30000 ) [virtual]

    Reimplemented from QIODevice::waitForBytesWritten().

    Look up this member in the source code.

    Toggle details bool QProcess

    waitForFinishedwaitForFinished ( int msecs=30000 ) ( int msecs=30000 )

    Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed.

    Returns true if the process finished; otherwise returns false (if the operation timed out, if an error occurred, or if this QProcess is already finished).

    This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.

    Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.

    If msecs is -1, this function will not time out.

    See also finished(), waitForStarted(), waitForReadyRead(), and waitForBytesWritten().

    Look up this member in the source code.

    Toggle details bool QProcess

    waitForReadyReadwaitForReadyRead ( int msecs=30000 ) ( int msecs=30000 ) [virtual]

    Reimplemented from QIODevice::waitForReadyRead().

    Look up this member in the source code.

    Toggle details bool QProcess

    waitForStartedwaitForStarted ( int msecs=30000 ) ( int msecs=30000 )

    Blocks until the process has started and the started() signal has been emitted, or until msecs milliseconds have passed.

    Returns true if the process was started successfully; otherwise returns false (if the operation timed out or if an error occurred).

    This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.

    Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.

    If msecs is -1, this function will not time out.

    See also started(), waitForReadyRead(), waitForBytesWritten(), and waitForFinished().

    Look up this member in the source code.

    Toggle details QString QProcess

    workingDirectoryworkingDirectory () ()const

    If QProcess has been assigned a working directory, this function returns the working directory that the QProcess will enter before the program has started. Otherwise, (i.e., no directory has been assigned,) an empty string is returned, and QProcess will use the application's current working directory instead.

    See also setWorkingDirectory().

    Look up this member in the source code.

    Toggle details qint64 QProcess

    writeDatawriteData ( const char *data , qint64 len ) ( const char *data , qint64 len ) [virtual protected]

    Reimplemented from QIODevice::writeData().

    Look up this member in the source code.

    Toggle details ProcessChannelMode QProcess

    readChannelModereadChannelMode () ()const Obsolete function

    Returns the read channel mode of the QProcess. This function is equivalent to processChannelMode()

    See also setReadChannelMode() and processChannelMode().

    Look up this member in the source code.

    Toggle details void QProcess

    setReadChannelModesetReadChannelMode ( ProcessChannelMode mode ) ( ProcessChannelMode mode ) Obsolete function

    Use setProcessChannelMode(mode) instead.

    See also readChannelMode() and setProcessChannelMode().

    Look up this member in the source code.

    Signals

    Toggle details void QProcess

    errorerror ( QProcess::ProcessError error ) ( QProcess::ProcessError error ) [signal]

    This signal is emitted when an error occurs with the process. The specified error describes the type of error that occurred.

    Look up this member in the source code.

    Toggle details void QProcess

    finishedfinished ( int exitCode , QProcess::ExitStatus exitStatus ...) ( int exitCode , QProcess::ExitStatus exitStatus ) [signal]

    This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished, the buffers in QProcess are still intact. You can still read any data that the process may have written before it finished.

    See also exitStatus().

    Look up this member in the source code.

    Toggle details void QProcess

    readyReadStandardErrorreadyReadStandardError () () [signal]

    This signal is emitted when the process has made new data available through its standard error channel (stderr). It is emitted regardless of the current read channel.

    See also readAllStandardError() and readChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    readyReadStandardOutputreadyReadStandardOutput () () [signal]

    This signal is emitted when the process has made new data available through its standard output channel (stdout). It is emitted regardless of the current read channel.

    See also readAllStandardOutput() and readChannel().

    Look up this member in the source code.

    Toggle details void QProcess

    startedstarted () () [signal]

    This signal is emitted by QProcess when the process has started, and state() returns Running.

    Look up this member in the source code.

    Toggle details void QProcess

    stateChangedstateChanged ( QProcess::ProcessState newState ( QProcess::ProcessState newState ) [signal]

    This signal is emitted whenever the state of QProcess changes. The newState argument is the state QProcess changed to.

    Look up this member in the source code.

    Toggle details void QProcess

    finishedfinished ( int exitCode ) ( int exitCode ) [signal] Obsolete function

    This is an overloaded function.

    Use finished(int exitCode, QProcess::ExitStatus status) instead.

    Look up this member in the source code.

    Public Slots

    Toggle details void QProcess

    killkill () () [slot]

    Kills the current process, causing it to exit immediately.

    On Windows, kill() uses TerminateProcess, and on Unix and Mac OS X, the SIGKILL signal is sent to the process.

    On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.

    See also Symbian Platform Security Requirements and terminate().

    Look up this member in the source code.

    Toggle details void QProcess

    terminateterminate () () [slot]

    Attempts to terminate the process.

    The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).

    On Windows, terminate() posts a WM_CLOSE message to all toplevel windows of the process and then to the main thread of the process itself. On Unix and Mac OS X the SIGTERM signal is sent.

    Console applications on Windows that do not run an event loop, or whose event loop does not handle the WM_CLOSE message, can only be terminated by calling kill().

    On Symbian, this function requires platform security capability PowerMgmt. If absent, the process will panic with KERN-EXEC 46.

    Note: Terminating running processes from other processes will typically cause a panic in Symbian due to platform security.

    See also Symbian Platform Security Requirements and kill().

    Look up this member in the source code.

    Notes provided by the Qt Community

    No notes