QProcess Class Reference |
Constant | Value | Description |
---|---|---|
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().
This enum describes the process channel modes of QProcess. Pass one of these values to setReadChannelMode() to set the current read channel mode.
Constant | Value | Description |
---|---|---|
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 setReadChannelMode().
This enum describes the different types of errors that are reported by QProcess.
Constant | Value | Description |
---|---|---|
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().
This enum describes the different states of QProcess.
Constant | Value | Description |
---|---|---|
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().
Constructs a QProcess object with the given parent.
Destructs the QProcess object.
Closes all communication with the process. After calling this function, QProcess will no longer emit readyRead(), and data can no longer be read or written.
Reimplemented from QIODevice.
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().
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:
QProcess more; more.start("more"); more.write("Text to display"); more.closeWriteChannel(); // QProcess will emit readyRead() once "more" starts printing
The write channel is implicitly opened when start() is called.
See also closeReadChannel().
Returns the environment that QProcess will use when starting a process, or an empty QStringList if no environment has been set. If no environment has been set, the environment of the calling process will be used.
See also setEnvironment().
Returns the type of error that occurred last.
See also state().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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 by the calling process.
On Windows, arguments that contain spaces are wrapped in quotes.
This is an overloaded member function, provided for convenience. It behaves essentially like the above 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.
Returns the exit code of the last process that finished.
This signal is emitted when the process finishes. exitCode is the exit code of the process. 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.
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.
See also terminate().
Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned.
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().
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().
Returns the current read channel of the QProcess.
See also setReadChannel().
Returns the read channel mode of the QProcess.
See also setReadChannelMode(), ProcessChannelMode, and setReadChannel().
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().
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().
Sets the environment that QProcess will use when starting a process to environment.
See also environment().
Sets the current state of the QProcess to the state specified.
See also state().
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().
Changing the read channel will clear the unget buffer.
See also readChannel().
Sets the read channel mode of the QProcess to the mode specified. This mode will be used the next time start() is called. For example:
QProcess builder; builder.setReadChannelMode(QProcess::MergedChannels); builder.start("make", QStringList() << "-j2"); if (!builder.waitForFinished()) qDebug() << "Make failed:" << builder.errorString(); else qDebug() << "Make output:" << builder.readAll();
See also readChannelMode(), ProcessChannelMode, and setReadChannel().
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.
See also workingDirectory() and start().
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:
class SandboxProcess : public QProcess { ... protected: void setupChildProcess(); ... }; void SandboxProcess::setupChildProcess() { // Drop all privileges in the child process, and enter // a chroot jail. #if defined Q_OS_UNIX ::setgroups(0, 0); ::chroot("/etc/safe"); ::chdir("/"); ::setgid(safeGid); ::setuid(safeUid); ::umask(0); #endif }
Warning: This function is called by QProcess on Unix and Mac OS X only. On Windows, it is not called.
Starts the program program in a new process, passing the command line arguments in arguments. The OpenMode is set to mode. QProcess will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, error() will be emitted.
On Windows, arguments that contain spaces are wrapped in quotes.
This is an overloaded member function, provided for convenience. It behaves essentially like the above 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. For example:
QProcess process; process.start("del /s *.txt"); // same as process.start("del", QStringList() << "/s" << "*.txt"); ...
The program string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example:
QProcess process; process.start("dir \"My Documents\"");
The OpenMode is set to mode.
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.
On Unix, the started process will run in its own session and act like a daemon. On Windows, it will run as a regular standalone process.
On Windows, arguments that contain spaces are wrapped in quotes.
This is an overloaded member function, provided for convenience. It behaves essentially like the above 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.
This signal is emitted by QProcess when the process has started, and state() returns Running.
Returns the current state of the process.
See also stateChanged() and error().
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 the process, and on Unix and Mac OS X the SIGTERM signal is sent.
See also kill().
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 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 finished(), waitForStarted(), waitForReadyRead(), and waitForBytesWritten().
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().
Returns the working directory that the QProcess will enter before the program has started.
See also setWorkingDirectory().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com