diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-07-24 15:09:38 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-24 15:09:38 +0200 |
commit | 509ed01c85c926387f6573dd1b5fe6611fa08118 (patch) | |
tree | cdc2b8a7df4c9778176a1e3341d018971f769daa /src/corelib/io/qprocess.cpp | |
parent | 288e50227dd5af7cdaba7e4b54a61c539021f1e0 (diff) | |
parent | 084c5b3db794af1ce86b2b17455d9be5e64baebe (diff) |
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r-- | src/corelib/io/qprocess.cpp | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index b1861d8038..1be108d0a7 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -727,9 +727,11 @@ void QProcessPrivate::Channel::clear() \fn void QProcess::finished(int exitCode, QProcess::ExitStatus exitStatus) This signal is emitted when the process finishes. \a exitCode is the exit - code of the process, and \a exitStatus is the exit status. 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. + code of the process (only valid for normal exits), and \a exitStatus is + the exit status. + 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. \sa exitStatus() */ @@ -1959,7 +1961,7 @@ void QProcess::start(const QString &program, const QStringList &arguments, OpenM d->program = program; d->arguments = arguments; - open(mode); + d->start(mode); } /*! @@ -1975,7 +1977,17 @@ void QProcess::start(const QString &program, const QStringList &arguments, OpenM */ void QProcess::start(OpenMode mode) { - open(mode); + Q_D(QProcess); + if (d->processState != NotRunning) { + qWarning("QProcess::start: Process is already running"); + return; + } + if (d->program.isEmpty()) { + qWarning("QProcess::start: program not set"); + return; + } + + d->start(mode); } /*! @@ -2008,34 +2020,39 @@ bool QProcess::open(OpenMode mode) return false; } + d->start(mode); + return true; +} + +void QProcessPrivate::start(QIODevice::OpenMode mode) +{ + Q_Q(QProcess); #if defined QPROCESS_DEBUG qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')'; #endif - d->outputReadBuffer.clear(); - d->errorReadBuffer.clear(); + outputReadBuffer.clear(); + errorReadBuffer.clear(); - if (d->stdinChannel.type != QProcessPrivate::Channel::Normal) - mode &= ~WriteOnly; // not open for writing - if (d->stdoutChannel.type != QProcessPrivate::Channel::Normal && - (d->stderrChannel.type != QProcessPrivate::Channel::Normal || - d->processChannelMode == MergedChannels)) - mode &= ~ReadOnly; // not open for reading + if (stdinChannel.type != QProcessPrivate::Channel::Normal) + mode &= ~QIODevice::WriteOnly; // not open for writing + if (stdoutChannel.type != QProcessPrivate::Channel::Normal && + (stderrChannel.type != QProcessPrivate::Channel::Normal || + processChannelMode == QProcess::MergedChannels)) + mode &= ~QIODevice::ReadOnly; // not open for reading if (mode == 0) - mode = Unbuffered; - QIODevice::open(mode); - - d->stdinChannel.closed = false; - d->stdoutChannel.closed = false; - d->stderrChannel.closed = false; + mode = QIODevice::Unbuffered; + q->QIODevice::open(mode); - d->exitCode = 0; - d->exitStatus = NormalExit; - d->processError = QProcess::UnknownError; - d->errorString.clear(); - d->startProcess(); + stdinChannel.closed = false; + stdoutChannel.closed = false; + stderrChannel.closed = false; - return true; + exitCode = 0; + exitStatus = QProcess::NormalExit; + processError = QProcess::UnknownError; + errorString.clear(); + startProcess(); } @@ -2219,6 +2236,8 @@ void QProcess::kill() /*! Returns the exit code of the last process that finished. + + This value is not valid unless exitStatus() returns NormalExit. */ int QProcess::exitCode() const { |