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

📄 qprocess.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
*/void QProcess::closeWriteChannel(){    Q_D(QProcess);    d->stdinChannel.closed = true; // closing    if (d->writeBuffer.isEmpty())        d->closeWriteChannel();}/*!    \since 4.2    Redirects the process' standard input to the file indicated by \a    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 \a 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.    \sa setStandardOutputFile(), setStandardErrorFile(),        setStandardOutputProcess()*/void QProcess::setStandardInputFile(const QString &fileName){    Q_D(QProcess);    d->stdinChannel = fileName;}/*!    \since 4.2    Redirects the process' standard output to the file \a    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 \a 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 \a mode is QIODevice::Truncate, the file    will be truncated. Otherwise (if \a mode is QIODevice::Append),    the file will be appended to.    Calling setStandardOutputFile() after the process has started has    no effect.    \sa setStandardInputFile(), setStandardErrorFile(),        setStandardOutputProcess()*/void QProcess::setStandardOutputFile(const QString &fileName, OpenMode mode){    Q_ASSERT(mode == Append || mode == Truncate);    Q_D(QProcess);    d->stdoutChannel = fileName;    d->stdoutChannel.append = mode == Append;}/*!    \since 4.2    Redirects the process' standard error to the file \a    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 \a 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.    \sa setStandardInputFile(), setStandardOutputFile(),        setStandardOutputProcess()*/void QProcess::setStandardErrorFile(const QString &fileName, OpenMode mode){    Q_ASSERT(mode == Append || mode == Truncate);    Q_D(QProcess);    d->stderrChannel = fileName;    d->stderrChannel.append = mode == Append;}/*!    \since 4.2    Pipes the standard output stream of this process to the \a    destination process' standard input.    The following shell command:    \code        command1 | command2    \endcode    Can be accomplished with QProcesses with the following code:    \code        QProcess process1;        QProcess process2;        process1.setStandardOutputProcess(process2);        process1.start("command1");        process2.start("command2");    \endcode*/void QProcess::setStandardOutputProcess(QProcess *destination){    QProcessPrivate *dfrom = d_func();    QProcessPrivate *dto = destination->d_func();    dfrom->stdoutChannel.pipeTo(dto);    dto->stdinChannel.pipeFrom(dfrom);}/*!    Returns the working directory that the QProcess will enter before    the program has started.    \sa setWorkingDirectory()*/QString QProcess::workingDirectory() const{    Q_D(const QProcess);    return d->workingDirectory;}/*!    Sets the working directory to \a 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.    \sa workingDirectory(), start()*/void QProcess::setWorkingDirectory(const QString &dir){    Q_D(QProcess);    d->workingDirectory = dir;}/*!    Returns the native process identifier for the running process, if    available.  If no process is currently running, 0 is returned.*/Q_PID QProcess::pid() const{    Q_D(const QProcess);    return d->pid;}/*! \reimp    This function operates on the current read channel.    \sa readChannel(), setReadChannel()*/bool QProcess::canReadLine() const{    Q_D(const QProcess);    const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)                                    ? &d->errorReadBuffer                                    : &d->outputReadBuffer;    return readBuffer->canReadLine() || QIODevice::canReadLine();}/*!    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.*/void QProcess::close(){    emit aboutToClose();    while (waitForBytesWritten(-1))        ;    kill();    waitForFinished(-1);    setOpenMode(QIODevice::NotOpen);}/*! \reimp   Returns true if the process is not running, and no more data is available   for reading; otherwise returns false.*/bool QProcess::atEnd() const{    Q_D(const QProcess);    const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)                                    ? &d->errorReadBuffer                                    : &d->outputReadBuffer;    return QIODevice::atEnd() && (!isOpen() || readBuffer->isEmpty());}/*! \reimp*/bool QProcess::isSequential() const{    return true;}/*! \reimp*/qint64 QProcess::bytesAvailable() const{    Q_D(const QProcess);    const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)                                    ? &d->errorReadBuffer                                    : &d->outputReadBuffer;#if defined QPROCESS_DEBUG    qDebug("QProcess::bytesAvailable() == %i (%s)", readBuffer->size(),           (d->processChannel == QProcess::StandardError) ? "stderr" : "stdout");#endif    return readBuffer->size() + QIODevice::bytesAvailable();}/*! \reimp*/qint64 QProcess::bytesToWrite() const{    Q_D(const QProcess);    qint64 size = d->writeBuffer.size();#ifdef Q_OS_WIN    size += d->pipeWriterBytesToWrite();#endif    return size;}/*!    Returns the type of error that occurred last.    \sa state()*/QProcess::ProcessError QProcess::error() const{    Q_D(const QProcess);    return d->processError;}/*!    Returns the current state of the process.    \sa stateChanged(), error()*/QProcess::ProcessState QProcess::state() const{    Q_D(const QProcess);    return d->processState;}/*!    Sets the environment that QProcess will use when starting a process to the    \a environment specified which consists of a list of key=value pairs.    For example, the following code adds the \c{C:\\BIN} directory to the list of    executable paths (\c{PATHS}) on Windows:    \quotefromfile snippets/qprocess-environment/main.cpp    \skipto QProcess process;    \printuntil process.start    \sa environment(), systemEnvironment()*/void QProcess::setEnvironment(const QStringList &environment){    Q_D(QProcess);    d->environment = environment;}/*!    Returns the environment that QProcess will use when starting a    process, or an empty QStringList if no environment has been set    using setEnvironment(). If no environment has been set, the    environment of the calling process will be used.    \sa setEnvironment(), systemEnvironment()*/QStringList QProcess::environment() const{    Q_D(const QProcess);    return d->environment;}/*!    Blocks until the process has started and the started() signal has    been emitted, or until \a 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.    \sa started(), waitForReadyRead(), waitForBytesWritten(), waitForFinished()*/bool QProcess::waitForStarted(int msecs){    Q_D(QProcess);    if (d->processState == QProcess::Starting) {        if (!d->waitForStarted(msecs))            return false;        d->processState = QProcess::Running;        emit started();    }    return d->processState == QProcess::Running;}/*! \reimp*/bool QProcess::waitForReadyRead(int msecs){    Q_D(QProcess);    if (d->processState == QProcess::NotRunning)        return false;    if (d->processChannel == QProcess::StandardOutput && d->stdoutChannel.closed)        return false;    if (d->processChannel == QProcess::StandardError && d->stderrChannel.closed)        return false;    return d->waitForReadyRead(msecs);}/*! \reimp*/bool QProcess::waitForBytesWritten(int msecs){    Q_D(QProcess);    if (d->processState == QProcess::NotRunning)        return false;    if (d->processState == QProcess::Starting) {        QTime stopWatch;        stopWatch.start();        bool started = waitForStarted(msecs);        if (!started)            return false;        if (msecs != -1)            msecs -= stopWatch.elapsed();    }    return d->waitForBytesWritten(msecs);}/*!    Blocks until the process has finished and the finished() signal    has been emitted, or until \a 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.    \sa finished(), waitForStarted(), waitForReadyRead(), waitForBytesWritten()*/bool QProcess::waitForFinished(int msecs){    Q_D(QProcess);    if (d->processState == QProcess::NotRunning)        return false;    if (d->processState == QProcess::Starting) {        QTime stopWatch;        stopWatch.start();        bool started = waitForStarted(msecs);        if (!started)            return false;        if (msecs != -1)            msecs -= stopWatch.elapsed();    }    return d->waitForFinished(msecs);}/*!    Sets the current state of the QProcess to the \a state specified.    \sa state()*/void QProcess::setProcessState(ProcessState state){    Q_D(QProcess);    d->processState = state;}/*!  This function is called in the child process context just before the    program is executed on Unix or Mac OS X (i.e., after \e fork(), but before    \e execve()). Reimplement this function to do last minute initialization    of the child process. Example:    \code        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        }    \endcode    \warning This function is called by QProcess on Unix and Mac OS X    only. On Windows, it is not called.*/void QProcess::setupChildProcess(){}/*! \reimp*/qint64 QProcess::readData(char *data, qint64 maxlen){    Q_D(QProcess);    QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)                              ? &d->errorReadBuffer                              : &d->outputReadBuffer;    if (maxlen == 1) {        int c = readBuffer->getChar();        if (c == -1) {

⌨️ 快捷键说明

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