summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r--src/corelib/io/qprocess.cpp69
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
{