⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qprocess.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include <stdio.h>#include <stdlib.h>#include "qprocess.h"#ifndef QT_NO_PROCESS#include "qapplication.h"//#define QT_QPROCESS_DEBUG/*!  \class QProcess qprocess.h  \brief The QProcess class is used to start external programs and to  communicate with them.  First availability: Qtopia 1.6  \ingroup qtopiaemb*//*!  \enum QProcess::Communication  This enum type defines the communication channels connected to the  process.  \value Stdin  Data can be written to the process's standard input.  \value Stdout  Data can be read from the process's standard output.  \value Stderr  Data can be read from the process's standard error.  \value DupStderr  Duplicates standard error to standard output for new  processes; i.e.  everything that the process writes to standard error, is  reported by QProcess on standard output instead. This is especially useful if  your application requires that the output on standard output and standard  error is read in the same order as the process output it. Please note that  this is a binary flag, so if you want to activate this together with standard  input, output and error redirection (the default), you have to specify  \c{Stdin|Stdout|Stderr|DupStderr} for the setCommunication() call.  \sa setCommunication() communication()*//*!  Constructs a QProcess object. The \a parent and \a name parameters are passed  to the QObject constructor.  \sa setArguments() addArgument() start()*/QProcess::QProcess( QObject *parent, const char *name )    : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),    wroteToStdinConnected( FALSE ),    readStdoutCalled( FALSE ), readStderrCalled( FALSE ),    comms( Stdin|Stdout|Stderr ){    init();}/*!  Constructs a QProcess with \a arg0 as the command to be executed. The  \a parent and \a name parameters are passed to the QObject constructor.  The process is not started. You must call start() or launch()  to start the process.  \sa setArguments() addArgument() start()*/QProcess::QProcess( const QString& arg0, QObject *parent, const char *name )    : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),    wroteToStdinConnected( FALSE ),    readStdoutCalled( FALSE ), readStderrCalled( FALSE ),    comms( Stdin|Stdout|Stderr ){    init();    addArgument( arg0 );}/*!  Constructs a QProcess with \a args as the arguments of the process. The first  element in the list is the command to be executed. The other elements in the  list are the arguments to this command. The \a parent and \a name  parameters are passed to the QObject constructor.  The process is not started. You must call start() or launch()  to start the process.  \sa setArguments() addArgument() start()*/QProcess::QProcess( const QStringList& args, QObject *parent, const char *name )    : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),    wroteToStdinConnected( FALSE ),    readStdoutCalled( FALSE ), readStderrCalled( FALSE ),    comms( Stdin|Stdout|Stderr ){    init();    setArguments( args );}/*!  Returns the list of arguments that are set for the process. Arguments can be  specified with the constructor or with the functions setArguments() and  addArgument().  \sa setArguments() addArgument()*/QStringList QProcess::arguments() const{    return _arguments;}/*!  Clears the list of arguments that are set for the process.  \sa setArguments() addArgument()*/void QProcess::clearArguments(){    _arguments.clear();}/*!  Sets \a args as the arguments for the process. The first element in the list  is the command to be executed. The other elements in the list are the  arguments to the command. Any previous arguments are deleted.  \sa arguments() addArgument()*/void QProcess::setArguments( const QStringList& args ){    _arguments = args;}/*!  Adds \a arg to the end of the list of arguments.  The first element in the list of arguments is the command to be  executed; the following elements are the arguments to the command.  \sa arguments() setArguments()*/void QProcess::addArgument( const QString& arg ){    _arguments.append( arg );}#ifndef QT_NO_DIR/*!  Returns the working directory that was set with  setWorkingDirectory(), or the current directory if none has been  set.  \sa setWorkingDirectory()*/QDir QProcess::workingDirectory() const{    return workingDir;}/*!  Sets \a dir as the working directory for a process. This does not affect  running processes; only processes that are started afterwards are affected.  Setting the working directory is especially useful for processes that try to  access files with relative filenames.  \sa workingDirectory() start()*/void QProcess::setWorkingDirectory( const QDir& dir ){    workingDir = dir;}#endif //QT_NO_DIR/*!  Returns the communication required with the process.  \sa setCommunication()*/int QProcess::communication() const{    return comms;}/*!  Sets \a commFlags as the communication required with the process.  \a commFlags is a bitwise OR between the flags defined in \c Communication.  The default is \c{Stdin|Stdout|Stderr}.  \sa communication()*/void QProcess::setCommunication( int commFlags ){    comms = commFlags;}/*!  Returns TRUE if the process has exited normally; otherwise returns  FALSE. This implies that this function returns FALSE if the process  is still running.  \sa isRunning() exitStatus() processExited()*/bool QProcess::normalExit() const{    // isRunning() has the side effect that it determines the exit status!    if ( isRunning() )	return FALSE;    else	return exitNormal;}/*!  Returns the exit status of the process or 0 if the process is still  running. This function returns immediately and does not wait until  the process is finished.  If normalExit() is FALSE (e.g. if the program was killed or  crashed), this function returns 0, so you should check the return  value of normalExit() before relying on this value.  \sa normalExit() processExited()*/int QProcess::exitStatus() const{    // isRunning() has the side effect that it determines the exit status!    if ( isRunning() )	return 0;    else	return exitStat;}/*!  Reads the data that the process has written to standard output. When  new data is written to standard output, the class emits the signal  readyReadStdout().  If there is no data to read, this function returns a QByteArray of  size 0: it does not wait until there is something to read.  \sa readyReadStdout() readLineStdout() readStderr() writeToStdin()*/QByteArray QProcess::readStdout(){    if ( readStdoutCalled ) {	return QByteArray();    }    readStdoutCalled = TRUE;    QByteArray buf = bufStdout()->copy();    consumeBufStdout( -1 ); // consume everything    readStdoutCalled = FALSE;    return buf;}/*!  Reads the data that the process has written to standard error. When  new data is written to standard error, the class emits the signal  readyReadStderr().  If there is no data to read, this function returns a QByteArray of  size 0: it does not wait until there is something to read.  \sa readyReadStderr() readLineStderr() readStdout() writeToStdin()*/QByteArray QProcess::readStderr(){    if ( readStderrCalled ) {	return QByteArray();    }    readStderrCalled = TRUE;    QByteArray buf = bufStderr()->copy();    consumeBufStderr( -1 ); // consume everything    readStderrCalled = FALSE;    return buf;}/*!  Returns TRUE if it's possible to read an entire line of text from  standard output at this time; otherwise returns FALSE.  \sa readLineStdout() canReadLineStderr()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -