📄 qprocess.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/edba/dist/qtopia/main-Sunday/qtopia/src/libraries/qtopia1/qprocess.cpp:34 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QProcess Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="200" align="left" valign="top"><a href="index.html"><img height="27" width="472" src="dochead.png" border="0"></a><br><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qtopia</font> <a href="index.html">Home</a> - <a href="qtopiaclasses.html">Classes</a> - <a href="qtopiaannotated.html">Annotated</a> - <a href="qtopiafunctions.html">Functions</a> - <a href="qtindex.html">Qt Embedded</a></td><td align="right" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="137"> <tr> <td><a href="http://www.trolltech.com/company/about/trolls.html"><img height="100" width="100" src="face.png" border="0"></a></td> <td><img height="100" width="100" src="qtlogo.png" align="top" border="0"></td> </tr> </table></td></tr></table><h1 align=center>QProcess Class Reference</h1><p>The QProcess class is used to start external programs and tocommunicate with them.<a href="#details">More...</a><p><tt>#include <<a href="qprocess-h.html">qprocess.h</a>></tt><p><a href="qprocess-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QProcess"><b>QProcess</b></a> ( QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#QProcess-2"><b>QProcess</b></a> ( const QString & arg0, QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#QProcess-3"><b>QProcess</b></a> ( const QStringList & args, QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#~QProcess"><b>~QProcess</b></a> ()</div></li><li><div class=fn>QStringList <a href="#arguments"><b>arguments</b></a> () const</div></li><li><div class=fn>void <a href="#clearArguments"><b>clearArguments</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setArguments"><b>setArguments</b></a> ( const QStringList & args )</div></li><li><div class=fn>virtual void <a href="#addArgument"><b>addArgument</b></a> ( const QString & arg )</div></li><li><div class=fn>QDir <a href="#workingDirectory"><b>workingDirectory</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setWorkingDirectory"><b>setWorkingDirectory</b></a> ( const QDir & dir )</div></li><li><div class=fn>int <b>priority</b> () const</div></li><li><div class=fn>void <a href="#setPriority"><b>setPriority</b></a> ( int p )</div></li><li><div class=fn>enum <a href="#Communication-enum"><b>Communication</b></a> { Stdin = 0x01, Stdout = 0x02, Stderr = 0x04, DupStderr = 0x08 }</div></li><li><div class=fn>void <a href="#setCommunication"><b>setCommunication</b></a> ( int commFlags )</div></li><li><div class=fn>int <a href="#communication"><b>communication</b></a> () const</div></li><li><div class=fn>virtual bool <a href="#start"><b>start</b></a> ( QStringList * env = 0 )</div></li><li><div class=fn>virtual bool <a href="#launch-2"><b>launch</b></a> ( const QString & buf, QStringList * env = 0 )</div></li><li><div class=fn>virtual bool <a href="#launch"><b>launch</b></a> ( const QByteArray & buf, QStringList * env = 0 )</div></li><li><div class=fn>bool <a href="#isRunning"><b>isRunning</b></a> () const</div></li><li><div class=fn>bool <a href="#normalExit"><b>normalExit</b></a> () const</div></li><li><div class=fn>int <a href="#exitStatus"><b>exitStatus</b></a> () const</div></li><li><div class=fn>virtual QByteArray <a href="#readStdout"><b>readStdout</b></a> ()</div></li><li><div class=fn>virtual QByteArray <a href="#readStderr"><b>readStderr</b></a> ()</div></li><li><div class=fn>bool <a href="#canReadLineStdout"><b>canReadLineStdout</b></a> () const</div></li><li><div class=fn>bool <a href="#canReadLineStderr"><b>canReadLineStderr</b></a> () const</div></li><li><div class=fn>virtual QString <a href="#readLineStdout"><b>readLineStdout</b></a> ()</div></li><li><div class=fn>virtual QString <a href="#readLineStderr"><b>readLineStderr</b></a> ()</div></li><li><div class=fn>typedef long <b>Q_LONG</b></div></li><li><div class=fn>PID <a href="#processIdentifier"><b>processIdentifier</b></a> ()</div></li></ul><h2>Public Slots</h2><ul><li><div class=fn>void <a href="#tryTerminate"><b>tryTerminate</b></a> () const</div></li><li><div class=fn>void <a href="#kill"><b>kill</b></a> () const</div></li><li><div class=fn>virtual void <a href="#writeToStdin"><b>writeToStdin</b></a> ( const QByteArray & buf )</div></li><li><div class=fn>virtual void <a href="#writeToStdin-2"><b>writeToStdin</b></a> ( const QString & buf )</div></li><li><div class=fn>virtual void <a href="#closeStdin"><b>closeStdin</b></a> ()</div></li></ul><h2>Signals</h2><ul><li><div class=fn>void <a href="#readyReadStdout"><b>readyReadStdout</b></a> ()</div></li><li><div class=fn>void <a href="#readyReadStderr"><b>readyReadStderr</b></a> ()</div></li><li><div class=fn>void <a href="#processExited"><b>processExited</b></a> ()</div></li><li><div class=fn>void <a href="#wroteToStdin"><b>wroteToStdin</b></a> ()</div></li><li><div class=fn>void <a href="#launchFinished"><b>launchFinished</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2><p> The QProcess class is used to start external programs and tocommunicate with them.<p> First availability: Qtopia 1.6<p> <p>See also <a href="qtopiaemb.html">Qtopia Classes</a>.<hr><h2>Member Type Documentation</h2><h3 class=fn><a name="Communication-enum"></a>QProcess::Communication</h3><p> This enum type defines the communication channels connected to theprocess.<ul><li><tt>QProcess::Stdin</tt> - Data can be written to the process's standard input.<li><tt>QProcess::Stdout</tt> - Data can be read from the process's standard output.<li><tt>QProcess::Stderr</tt> - Data can be read from the process's standard error.<li><tt>QProcess::DupStderr</tt> - Duplicates standard error to standard output for newprocesses; i.e. everything that the process writes to standard error, isreported by QProcess on standard output instead. This is especially useful ifyour application requires that the output on standard output and standarderror is read in the same order as the process output it. Please note thatthis is a binary flag, so if you want to activate this together with standardinput, output and error redirection (the default), you have to specify<tt>Stdin|Stdout|Stderr|DupStderr</tt> for the <a href="#setCommunication">setCommunication</a>() call.</ul><p> <p>See also <a href="#setCommunication">setCommunication</a>() and <a href="#communication">communication</a>().<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QProcess"></a>QProcess::QProcess ( QObject * parent = 0, const char * name = 0 )</h3>Constructs a QProcess object. The <em>parent</em> and <em>name</em> parameters are passedto the QObject constructor.<p> <p>See also <a href="#setArguments">setArguments</a>(), <a href="#addArgument">addArgument</a>() and <a href="#start">start</a>().<h3 class=fn><a name="QProcess-2"></a>QProcess::QProcess ( const QString & arg0, QObject * parent = 0, const char * name = 0 )</h3>Constructs a QProcess with <em>arg0</em> as the command to be executed. The<em>parent</em> and <em>name</em> parameters are passed to the QObject constructor.<p> The process is not started. You must call <a href="#start">start</a>() or <a href="#launch">launch</a>()to start the process.<p> <p>See also <a href="#setArguments">setArguments</a>(), <a href="#addArgument">addArgument</a>() and <a href="#start">start</a>().<h3 class=fn><a name="QProcess-3"></a>QProcess::QProcess ( const QStringList & args, QObject * parent = 0, const char * name = 0 )</h3>Constructs a QProcess with <em>args</em> as the arguments of the process. The firstelement in the list is the command to be executed. The other elements in thelist are the arguments to this command. The <em>parent</em> and <em>name</em>parameters are passed to the QObject constructor.<p> The process is not started. You must call <a href="#start">start</a>() or <a href="#launch">launch</a>()to start the process.<p> <p>See also <a href="#setArguments">setArguments</a>(), <a href="#addArgument">addArgument</a>() and <a href="#start">start</a>().<h3 class=fn><a name="~QProcess"></a>QProcess::~QProcess ()</h3>Destroys the class.<p> If the process is running, it is NOT terminated! Standard input, standardoutput and standard error of the process are closed.<p> You can connect the destroyed() signal to the <a href="#kill">kill</a>() slot, if you want theprocess to be terminated automatically when the class is destroyed.<p> <p>See also <a href="#tryTerminate">tryTerminate</a>() and <a href="#kill">kill</a>().<h3 class=fn>void <a name="addArgument"></a>QProcess::addArgument ( const QString & arg )<tt> [virtual]</tt></h3>Adds <em>arg</em> to the end of the list of arguments.<p> The first element in the list of arguments is the command to beexecuted; the following elements are the arguments to the command.<p> <p>See also <a href="#arguments">arguments</a>() and <a href="#setArguments">setArguments</a>().<h3 class=fn>QStringList <a name="arguments"></a>QProcess::arguments () const</h3>Returns the list of arguments that are set for the process. Arguments can bespecified with the constructor or with the functions <a href="#setArguments">setArguments</a>() and<a href="#addArgument">addArgument</a>().<p> <p>See also <a href="#setArguments">setArguments</a>() and <a href="#addArgument">addArgument</a>().<h3 class=fn>bool <a name="canReadLineStderr"></a>QProcess::canReadLineStderr () const</h3>Returns TRUE if it's possible to read an entire line of text fromstandard error at this time; otherwise returns FALSE.<p> <p>See also <a href="#readLineStderr">readLineStderr</a>() and <a href="#canReadLineStdout">canReadLineStdout</a>().<h3 class=fn>bool <a name="canReadLineStdout"></a>QProcess::canReadLineStdout () const</h3>Returns TRUE if it's possible to read an entire line of text fromstandard output at this time; otherwise returns FALSE.<p> <p>See also <a href="#readLineStdout">readLineStdout</a>() and <a href="#canReadLineStderr">canReadLineStderr</a>().<h3 class=fn>void <a name="clearArguments"></a>QProcess::clearArguments ()</h3>Clears the list of arguments that are set for the process.<p> <p>See also <a href="#setArguments">setArguments</a>() and <a href="#addArgument">addArgument</a>().<h3 class=fn>void <a name="closeStdin"></a>QProcess::closeStdin ()<tt> [virtual slot]</tt></h3>Closes standard input of the process.<p> This function also deletes pending data that is not written to standard inputyet.<p> <p>See also <a href="#wroteToStdin">wroteToStdin</a>().<h3 class=fn>int <a name="communication"></a>QProcess::communication () const</h3>Returns the communication required with the process.<p> <p>See also <a href="#setCommunication">setCommunication</a>().<h3 class=fn>int <a name="exitStatus"></a>QProcess::exitStatus () const</h3>Returns the exit status of the process or 0 if the process is stillrunning. This function returns immediately and does not wait untilthe process is finished.<p> If <a href="#normalExit">normalExit</a>() is FALSE (e.g. if the program was killed orcrashed), this function returns 0, so you should check the returnvalue of normalExit() before relying on this value.<p> <p>See also <a href="#normalExit">normalExit</a>() and <a href="#processExited">processExited</a>().<h3 class=fn>bool <a name="isRunning"></a>QProcess::isRunning () const</h3>Returns TRUE if the process is running, otherwise FALSE.<p> <p>See also <a href="#normalExit">normalExit</a>(), <a href="#exitStatus">exitStatus</a>() and <a href="#processExited">processExited</a>().<h3 class=fn>void <a name="kill"></a>QProcess::kill () const<tt> [slot]</tt></h3>Terminates the process. This is not a safe way to end a process since theprocess will not be able to do cleanup. <a href="#tryTerminate">tryTerminate</a>() is a safer way to doit, but processes might ignore a tryTerminate().<p> The nice way to end a process and to be sure that it is finished, is doingsomething like this:<pre> process->tryTerminate(); QTimer::singleShot( 5000, process, SLOT( <a href="#kill">kill</a>() ) ); </pre> <p> This tries to terminate the process the nice way. If the process is stillrunning after 5 seconds, it terminates the process the hard way. The timeoutshould be chosen depending on the time the process needs to do all thecleanup: use a higher value if the process is likely to do heavy computationon cleanup.<p> The slot returns immediately: it does not wait until the process hasfinished. When the process really exited, the signal <a href="#processExited">processExited</a>() isemitted.<p> <p>See also <a href="#tryTerminate">tryTerminate</a>() and <a href="#processExited">processExited</a>().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -