qt有没有类似于qt的软件shellexecute的

在Qt中用默认程序打开文件-中国学网-中国IT综合门户网站-提供健康,养生,留学,移民,创业,汽车等信息
在Qt中用默认程序打开文件
来源:互联网 更新时间: 12:47:15 责任编辑:鲁晓倩字体:
用法:&&&&QProcess::execute("explorer 文件名");例:&&&&&&&&QProcess::execute("explorer c:\\123.txt");&----------------------------------------------------------------------&应该早有大虾发现了这个方法,只是我没搜到,于是有了下面这篇聒噪的探索文章。&如何在Qt中用默认程序打开文件。比如给个"123.html"参数,就能用浏览器打开。网上搜了一下,多数的解决方法是用ShellExecute这个Windows Api函数。可行,但总希望能找到一个Qt的Api来使用。继续找资料。发现一个QProcess类。测试QProcess::execute("notepad.exe");成功打开记事本。以为有戏。。接着测试 --- ---QProcess::execute("start c:\\123.txt");失败了。。心凉了半截。查看QProcess::execute代码,发现最终其实就是调用windows的CreateProcess函数。start估计不是个程序,只是个命令,所以报了个无法找到程序的错误。反过来说只要找到一个程序,这个程序能用默认程序打开文件就行了。继续找资料。在一大堆信息中苦苦寻找,终于在一个角落发现有人提到了explorer.exe。很熟悉的名字吧。这个就是windows的文件资源管理器。打开进程管理器,总会见到几个在运行。地址如下(感谢那位网友)冥冥之中,有个声音在对我说,这就是解决问题的钥匙了。^-^接着查找explorer.exe的参数用法。闲话少说,经过在cmd一番测试。得出用法是explorer filename.例:explorer c:\123.txt加不加引号随意,要注意的是用反斜杠,在cmd窗口只用一杠就行了,否则就会打开我的文档。&在Qt中测试代码QProcess::execute("explorer c:\\123.txt");成功打开!开心^-^
相关文章:
上一篇文章:下一篇文章:
最新添加资讯
24小时热门资讯
Copyright © 2004- All Rights Reserved. 中国学网 版权所有
京ICP备号-1 京公网安备02号QProcess Class | Qt Core 5.6
QProcess Class
class is used to start external programs and to communicate with them.
Header: #include &QProcess&
qmake: QT += core Inherits: Note: All functions in this class are .
Public Types
{ NormalExit, CrashExit }
{ ManagedInputChannel, ForwardedInputChannel }
{ StandardOutput, StandardError }
{ SeparateChannels, MergedChannels, ForwardedChannels, ForwardedErrorChannel, ForwardedOutputChannel }
{ FailedToStart, Crashed, Timedout, WriteError, ReadError, UnknownError }
{ NotRunning, Starting, Running }
Public Functions
(QObject *parent = Q_NULLPTR)
virtual ()
QStringList () const
void (ProcessChannel channel)
QProcess::ProcessError () const
int () const
QProcess::ExitStatus () const
InputChannelMode () const
QString () const
ProcessChannelMode () const
QProcessEnvironment () const
qint64 () const
QString () const
QByteArray ()
QByteArray ()
ProcessChannel () const
void (const QStringList &arguments)
void (InputChannelMode mode)
void (const QString &arguments)
void (ProcessChannelMode mode)
void (const QProcessEnvironment &environment)
void (const QString &program)
void (ProcessChannel channel)
void (const QString &fileName, OpenMode mode = Truncate)
void (const QString &fileName)
void (const QString &fileName, OpenMode mode = Truncate)
void (QProcess *destination)
void (const QString &dir)
void (const QString &program, const QStringList &arguments, OpenMode mode = ReadWrite)
void (const QString &command, OpenMode mode = ReadWrite)
void (OpenMode mode = ReadWrite)
QProcess::ProcessState () const
bool (int msecs = 30000)
bool (int msecs = 30000)
QString () const
Reimplemented Public Functions
virtual bool () const
virtual qint64 () const
virtual qint64 () const
virtual bool () const
virtual void ()
virtual bool () const
virtual bool (OpenMode mode = ReadWrite)
virtual bool (int msecs = 30000)
virtual bool (int msecs = 30000)
33 public functions inherited from
31 public functions inherited from
Public Slots
1 public slot inherited from
void (QProcess::ProcessError error)
void (int exitCode, QProcess::ExitStatus exitStatus)
void (QProcess::ProcessState newState)
4 signals inherited from
2 signals inherited from
Static Public Members
int (const QString &program, const QStringList &arguments)
int (const QString &command)
QString ()
bool (const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = Q_NULLPTR)
bool (const QString &command)
QStringList ()
11 static public members inherited from
Protected Functions
void (ProcessState state)
virtual void ()
Reimplemented Protected Functions
virtual qint64 (char *data, qint64 maxlen)
virtual qint64 (const char *data, qint64 len)
5 protected functions inherited from
9 protected functions inherited from
Related Non-Members
Additional Inherited Members
1 property inherited from
Detailed Description
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 (). Arguments are supplied as individual strings in a .
Alternatively, you can set the program to run with () and (), and then call () or ().
For example, the following code snippet runs the analog clock example in the Fusion style on X11 platforms by passing strings containing &-style& and &fusion& as two items in the list of arguments:
program = &./path/to/Qt/examples/widgets/analogclock&;
arguments && &-style& && &fusion&;
*myProcess = new (parent);
myProcess-&start(program, arguments);
then enters the
state, and when the program has started,
enters the
state and emits ().
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 . You can then write to the process's standard input by calling (), and read the standard output by calling (), (), and (). Because it inherits ,
can also be used as an input source for , or for generating data to be uploaded using .
Note: On Windows CE, reading and writing to a process is not supported.When the process exits,
reenters the
state (the initial state), and emits ().
The () signal provides the exit code and exit status of the process as arguments, and you can also call () to obtain the exit code of the last process that finished, and () to obtain its exit status. If an error occurs at any point in time,
will emit the () signal. You can also call () to find the type of error that occurred last, and () 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 ().
emits () when data is available on the current read channel. It also emits () when new standard output data is available, and when new standard error data is available, () is emitted. Instead of calling (), (), or (), you can explicitly read all data from either of the two channels by calling () or ().
The terminology for the channels can be misleading. Be aware that the process's output channels correspond to 's read channels, whereas the process's input channels correspond to 's write channels. This is because what we read using
is the process's output, and what we write becomes the process's input.
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 () with
before starting the process to activate this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing
as the argument. It is also possible to forward only one of the output channels - typically one would use , but
also exists. Note that using channel forwarding is typically a bad idea in GUI applications - you should present errors graphically instead.
Certain processes need special environment settings in order to operate. You can set environment variables for your process by calling (). To set a working directory, call (). By default, processes are run in the current working directory of the calling process.
The positioning and the screen Z-order of windows belonging to GUI applications started with
are controlled by the underlying windowing system. For Qt 5 applications, the positioning can be specified using the -qwindowgeometry X11 applications generally accept a -geometry command line option.
Note: On QNX, setting the working directory may cause all application threads, with the exception of the
caller thread, to temporarily freeze during the spawning process, owing to a limitation in the operating system.
Synchronous Process API
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:
() blocks until the process has started.
() blocks until new data is available for reading on the current read channel.
() blocks until one payload of data has been written to the process.
() blocks until the process has finished.
Calling these functions from the main thread (the thread that calls ()) may cause your user interface to freeze.
The following example runs gzip to compress the string &Qt rocks!&, without an event loop:
gzip.start(&gzip&, () && &-c&);
if (!gzip.waitForStarted())
return false;
gzip.write(&Qt rocks!&);
gzip.closeWriteChannel();
if (!gzip.waitForFinished())
return false;
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
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.
See also , , and .
Member Type Documentation
enum QProcess::ExitStatus
This enum describes the different exit statuses of .
ConstantValueDescription
QProcess::NormalExit0The process exited normally.
QProcess::CrashExit1The process crashed.
See also ().
enum QProcess::InputChannelMode
This enum describes the process input channel modes of . Pass one of these values to () to set the current write channel mode.
ConstantValueDescription
QProcess::ManagedInputChannel0 manages the input of the running process. This is the default input channel mode of .
QProcess::ForwardedInputChannel1 forwards the input of the main process onto the running process. The child process reads its standard input from the same source as the main process. Note that the main process must not try to read its standard input while the child process is running.
This enum was introduced or modified in
See also ().
enum QProcess::ProcessChannel
This enum describes the process channels used by the running process. Pass one of these values to () to set the current read channel of .
ConstantValueDescription
QProcess::StandardOutput0The standard output (stdout) of the running process.
QProcess::StandardError1The standard error (stderr) of the running process.
See also ().
enum QProcess::ProcessChannelMode
This enum describes the process output channel modes of . Pass one of these values to () to set the current read channel mode.
ConstantValueDescription
QProcess::SeparateChannels0 manages the output of the running process, keeping standard output and standard error data in separate internal buffers. You can select the 's current read channel by calling (). This is the default channel mode of .
QProcess::MergedChannels1 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::ForwardedChannels2 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.
QProcess::ForwardedErrorChannel4 manages the standard output of the running process, but forwards its standard error onto the main process. This reflects the typical use of command line tools as filters, where the standard output is redirected to another process or a file, while standard error is printed to the console for diagnostic purposes. (This value was introduced in Qt 5.2.)
QProcess::ForwardedOutputChannel3Complementary to ForwardedErrorChannel. (This value was introduced in Qt 5.2.)
Note: Windows intentionally suppresses output from GUI-only applications to inherited consoles. This does not apply to output redirected to files or pipes. To forward the output of GUI-only applications on the console nonetheless, you must use SeparateChannels and do the forwarding yourself by reading the output and writing it to the appropriate output channels.See also ().
enum QProcess::ProcessError
This enum describes the different types of errors that are reported by .
ConstantValueDescription
QProcess::FailedToStart0The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
QProcess::Crashed1The process crashed some time after starting successfully.
QProcess::Timedout2The last waitFor...() function timed out. The state of
is unchanged, and you can try calling waitFor...() again.
QProcess::WriteError4An 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::ReadError3An error occurred when attempting to read from the process. For example, the process may not be running.
QProcess::UnknownError5An unknown error occurred. This is the default return value of ().
See also ().
enum QProcess::ProcessState
This enum describes the different states of .
ConstantValueDescription
QProcess::NotRunning0The process is not running.
QProcess::Starting1The process is starting, but the program has not yet been invoked.
QProcess::Running2The process is running and is ready for reading and writing.
See also ().
Member Function Documentation
QProcess::QProcess( *parent = Q_NULLPTR)
Constructs a
object with the given parent.
[virtual] QProcess::~QProcess()
Destructs the
object, i.e., killing the process.
Note that this function will not return until the process is terminated.
QProcess::arguments() const
Returns the command line arguments the process was last started with.
This function was introduced in
See also () and ().
[virtual] bool QProcess::atEnd() const
Reimplemented from ().
Returns true if the process is not running, and no more data is a otherwise returns false.
QProcess::bytesAvailable() const
Reimplemented from ().
QProcess::bytesToWrite() const
Reimplemented from ().
[virtual] bool QProcess::canReadLine() const
Reimplemented from ().
This function operates on the current read channel.
See also () and ().
[virtual] void QProcess::close()
Reimplemented from ().
Closes all communication with the process and kills it. After calling this function,
will no longer emit (), and data can no longer be read or written.
void QProcess::closeReadChannel( channel)
Closes the read channel channel. After calling this function,
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 () and ().
void QProcess::closeWriteChannel()
Schedules the write channel of
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 's write channel has been closed. Example:
more.start(&more&);
more.write(&Text to display&);
more.closeWriteChannel();
The write channel is implicitly opened when () is called.
See also ().
QProcess::error() const
Returns the type of error that occurred last.
See also ().
[signal] void QProcess::errorOccurred( error)
This signal is emitted when an error occurs with the process. The specified error describes the type of error that occurred.
This function was introduced in
[static] int QProcess::execute(const
&program, const
&arguments)
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.
Argument handling is identical to the respective () overload.
If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.
See also ().
[static] int QProcess::execute(const
This is an overloaded function.
Starts the program command in a new process, waits for it to finish, and then returns the exit code.
Argument handling is identical to the respective () overload.
After the command string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.
See also ().
int QProcess::exitCode() const
Returns the exit code of the last process that finished.
This value is not valid unless () returns .
QProcess::exitStatus() 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
unless the exit code is less than 0.
This function was introduced in
[signal] void QProcess::finished(int exitCode,
exitStatus)
This signal is emitted when the process finishes. exitCode is the exit code of the process (only valid for normal exits), and exitStatus is the exit status. After the process has finished, the buffers in
are still intact. You can still read any data that the process may have written before it finished.
Note:Signal finished is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(process, static_cast&void(::*)(int, ::ExitStatus)&(&::finished),
[=](int exitCode, ::ExitStatus exitStatus){
See also ().
QProcess::inputChannelMode() const
Returns the channel mode of the
standard input channel.
This function was introduced in
See also () and .
[virtual] bool QProcess::isSequential() const
Reimplemented from ().
[slot] void QProcess::kill()
Kills the current process, causing it to exit immediately.
On Windows, kill() uses TerminateProcess, and on Unix and OS X, the SIGKILL signal is sent to the process.
See also ().
QProcess::nativeArguments() const
Returns the additional native command line arguments for the program.
Note: This function is available only on the Windows platform.This function was introduced in
See also ().
QProcess::nullDevice()
The null device of the operating system.
The returned file path uses native directory separators.
This function was introduced in
See also (), (), and ().
[virtual] bool QProcess::open( mode = ReadWrite)
Reimplemented from ().
Starts the program set by () with arguments set by (). The
is set to mode.
This method is an alias for (), and exists only to fully implement the interface defined by .
See also (), (), and ().
QProcess::processChannelMode() const
Returns the channel mode of the
standard output and standard error channels.
This function was introduced in
See also (), , and ().
QProcess::processEnvironment() const
Returns the environment that
will pass to its child process, or an empty object if no environment has been set using setEnvironment() or (). 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.This function was introduced in
See also (), (), and ().
QProcess::processId() const
Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned.
This function was introduced in
QProcess::program() const
Returns the program the process was last started with.
This function was introduced in
See also () and ().
QProcess::readAllStandardError()
Regardless of the current read channel, this function returns all data available from the standard error of the process as a .
See also (), (), (), and ().
QProcess::readAllStandardOutput()
Regardless of the current read channel, this function returns all data available from the standard output of the process as a .
See also (), (), (), and ().
QProcess::readChannel() const
Returns the current read channel of the .
See also ().
[virtual protected]
QProcess::readData(char *data,
Reimplemented from ().
[signal] void QProcess::readyReadStandardError()
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 .
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
See also () and ().
[signal] void QProcess::readyReadStandardOutput()
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 .
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
See also () and ().
void QProcess::setArguments(const
&arguments)
Set the arguments to pass to the called program when starting the process. This function must be called before ().
This function was introduced in
See also (), (), and ().
void QProcess::setInputChannelMode( mode)
Sets the channel mode of the
standard input channel to the mode specified. This mode will be used the next time () is called.
This function was introduced in
See also () and .
void QProcess::setNativeArguments(const
&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 '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 platform.This function was introduced in
See also ().
void QProcess::setProcessChannelMode( mode)
Sets the channel mode of the
standard output and standard error channels to the mode specified. This mode will be used the next time () is called. For example:
builder.setProcessChannelMode(::MergedChannels);
builder.start(&make&, () && &-j2&);
if (!builder.waitForFinished())
() && &Make failed:& && builder.errorString();
() && &Make output:& && builder.readAll();
This function was introduced in
See also (), , and ().
void QProcess::setProcessEnvironment(const
&environment)
Sets the environment that
will pass to the child process.
For example, the following code adds the environment variable TMPDIR:
env = ::systemEnvironment();
env.insert(&TMPDIR&, &C:\\MyApp\\temp&);
process.setProcessEnvironment(env);
process.start(&myapp&);
Note how, on Windows, environment variable names are case-insensitive.
This function was introduced in
See also (), (), and ().
[protected] void QProcess::setProcessState( state)
Sets the current state of the
to the state specified.
See also ().
void QProcess::setProgram(const
Set the program to use when starting the process. This function must be called before ().
This function was introduced in
See also (), (), and ().
void QProcess::setReadChannel( channel)
Sets the current read channel of the
to the given channel. The current input channel is used by the functions (), (), (), and (). It also determines which channel triggers
to emit ().
See also ().
void QProcess::setStandardErrorFile(const
&fileName,
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 () will always fail, as will (). The file will be appended to if mode is Append, otherwise, it will be truncated.
See () for more information on how the file is opened.
Note: if () was called with an argument of , this function has no effect.
This function was introduced in
See also (), (), and ().
void QProcess::setStandardInputFile(const
&fileName)
Redirects the process' standard input to the file indicated by fileName. When an input redirection is in place, the
object will be in read-only mode (calling () will result in error).
To make the process read EOF right away, pass () here. This is cleaner than using () before writing any data, because it can be set up prior to starting the process.
If the file fileName does not exist at the moment () is called or is not readable, starting the process will fail.
Calling setStandardInputFile() after the process has started has no effect.
This function was introduced in
See also (), (), and ().
void QProcess::setStandardOutputFile(const
&fileName,
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 () will always fail, as will ().
To discard all standard output from the process, pass () here. This is more efficient than simply never reading the standard output, as no
buffers are filled.
If the file fileName doesn't exist at the moment () is called, it will be created. If it cannot be created, the starting will fail.
If the file exists and mode is , the file will be truncated. Otherwise (if mode is ), the file will be appended to.
Calling setStandardOutputFile() after the process has started has no effect.
This function was introduced in
See also (), (), and ().
void QProcess::setStandardOutputProcess( *destination)
Pipes the standard output stream of this process to the destination process' standard input.
The following shell command:
command1 | command2
Can be accomplished with
with the following code:
process1.setStandardOutputProcess(&process2);
process1.start(&command1&);
process2.start(&command2&);
This function was introduced in
void QProcess::setWorkingDirectory(const
Sets the working directory to dir.
will start the process in this directory. The default behavior is to start the process in the working directory of the calling process.
Note: On QNX, this may cause all application threads to temporarily freeze.See also () and ().
[virtual protected] void QProcess::setupChildProcess()
This function is called in the child process context just before the program is executed on Unix or 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
protected:
void setupChildProcess();
void SandboxProcess::setupChildProcess()
#if defined Q_OS_UNIX
::setgroups(0, 0);
::chroot(&/etc/safe&);
::chdir(&/&);
::setgid(safeGid);
::setuid(safeUid);
::umask(0);
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 () and then call exit().
Warning: This function is called by
on Unix and OS X only. On Windows and QNX, it is not called.
void QProcess::start(const
&program, const
&arguments,
mode = ReadWrite)
Starts the given program in a new process, passing the command line arguments in arguments.
object will immediately enter the Starting state. If the process starts successfully,
will emit (); otherwise, () will be emitted.
Note: Processes are started asynchronously, which means the () and () signals may be delayed. Call () 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: The arguments are quoted and joined into a command line that is compatible with the CommandLineToArgvW() Windows function. For programs that have different command line quoting requirements, you need to use (). One notable program that does not follow the CommandLineToArgvW() rules is cmd.exe and, by consequence, all batch scripts.
is set to mode.
object is already running a process, a warning may be printed at the console, and the existing process will continue running unaffected.
See also (), (), (), and ().
void QProcess::start(const
mode = ReadWrite)
This is an overloaded function.
Starts the command command in a new process. The
is set to mode.
command 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:
process.start(&del /s *.txt&);
Arguments containing spaces must be quoted to be correctly supplied to the new process. For example:
process.start(&dir \&My Documents\&&);
Literal quotes in the command string are represented by triple quotes. For example:
process.start(&dir \&Epic 12\&\&\& Singles\&&);
After the command string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.
You can disable this overload by defining QT_NO_PROCESS_COMBINED_ARGUMENT_START when you compile your applications. This can be useful if you want to ensure that you are not splitting arguments unintentionally, for example. In virtually all cases, using the other overload is the preferred method.
On operating systems where the system API for passing command line arguments to a subprocess natively uses a single string (Windows), one can conceive command lines which cannot be passed via 's portable list-based API. In these rare cases you need to use () and () instead of this function.
void QProcess::start( mode = ReadWrite)
This is an overloaded function.
Starts the program set by () with arguments set by (). The
is set to mode.
This function was introduced in
See also (), (), and ().
[static] bool QProcess::startDetached(const
&program, const
&arguments, const
&workingDirectory = QString(),
*pid = Q_NULLPTR)
Starts the program program with the arguments arguments in a new process, and detaches from it. Returns true otherwise returns false. If the calling process exits, the detached process will continue to run unaffected.
Argument handling is identical to the respective () overload.
Unix: The started process will run in its own session and act like a daemon.
The process will be started in the directory workingDirectory. If workingDirectory is empty, the working directory is inherited from the calling process.
Note: On QNX, this may cause all application threads to temporarily freeze.If the function is successful then *pid is set to the process identifier of the started process.
See also ().
[static] bool QProcess::startDetached(const
This is an overloaded function.
Starts the command command in a new process, and detaches from it. Returns true otherwise returns false.
Argument handling is identical to the respective () overload.
After the command string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.
See also ().
[signal] void QProcess::started()
This signal is emitted by
when the process has started, and () returns .
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
QProcess::state() const
Returns the current state of the process.
See also () and ().
[signal] void QProcess::stateChanged( newState)
This signal is emitted whenever the state of
changes. The newState argument is the state
changed to.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
QProcess::systemEnvironment()
Returns the environment of the calling process as a list of key=value pairs. Example:
environment = ::systemEnvironment();
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 or 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 ()This function was introduced in
See also () and ().
[slot] void QProcess::terminate()
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 top-level windows of the process and then to the main thread of the process itself. On Unix and 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 ().
See also ().
[virtual] bool QProcess::waitForBytesWritten(int msecs = 30000)
Reimplemented from ().
bool QProcess::waitForFinished(int msecs = 30000)
Blocks until the process has finished and the () signal has been emitted, or until msecs milliseconds have passed.
Returns true if
otherwise returns false (if the operation timed out, if an error occurred, or if this
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 (), (), (), and ().
[virtual] bool QProcess::waitForReadyRead(int msecs = 30000)
Reimplemented from ().
bool QProcess::waitForStarted(int msecs = 30000)
Blocks until the process has started and the () signal has been emitted, or until msecs milliseconds have passed.
Returns true if the process was
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.
Note: On some UNIX operating systems, this function may return true but the process may later report a
error.See also (), (), (), and ().
QProcess::workingDirectory() const
has been assigned a working directory, this function returns the working directory that the
will enter before the program has started. Otherwise, (i.e., no directory has been assigned,) an empty string is returned, and
will use the application's current working directory instead.
See also ().
[virtual protected]
QProcess::writeData(const char *data,
Reimplemented from ().
Related Non-Members
typedef Q_PID
Typedef for the identifiers used to represent processes on the underlying platform. On Unix,
on Windows, it corresponds to _PROCESS_INFORMATION*.
See also ().
Macro Documentation
QT_NO_PROCESS_COMBINED_ARGUMENT_START
Disables the () overload taking a single string. In most cases where it is used, the user intends for the first argument to be treated atomically as per the other overload.
This function was introduced in
See also ().
& 2016 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the
as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd.
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.}

我要回帖

更多关于 qt yy 类似 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信