summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qprocess.cpp19
-rw-r--r--src/corelib/io/qprocess.h5
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp48
3 files changed, 55 insertions, 17 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 8a1fda6ccb..17079bd1cc 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -502,8 +502,8 @@ void QProcessPrivate::Channel::clear()
the process as arguments, and you can also call exitCode() to
obtain the exit code of the last process that finished, and
exitStatus() to obtain its exit status. If an error occurs at
- any point in time, QProcess will emit the error() signal. You
- can also call error() to find the type of error that occurred
+ any point in time, QProcess will emit the errorOccurred() signal.
+ You can also call error() to find the type of error that occurred
last, and state() to find the current process state.
\section1 Communicating via Channels
@@ -740,6 +740,14 @@ void QProcessPrivate::Channel::clear()
/*!
\fn void QProcess::error(QProcess::ProcessError error)
+ \obsolete
+
+ Use errorOccurred() instead.
+*/
+
+/*!
+ \fn void QProcess::errorOccurred(QProcess::ProcessError error)
+ \since 5.6
This signal is emitted when an error occurs with the process. The
specified \a error describes the type of error that occurred.
@@ -940,6 +948,7 @@ void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError error, const QStrin
Q_Q(QProcess);
Q_ASSERT(error != QProcess::UnknownError);
setError(error, description);
+ emit q->errorOccurred(processError);
emit q->error(processError);
}
@@ -1094,7 +1103,7 @@ bool QProcessPrivate::_q_processDied()
// the process may have died before it got a chance to report that it was
// either running or stopped, so we will call _q_startupNotification() and
- // give it a chance to emit started() or error(FailedToStart).
+ // give it a chance to emit started() or errorOccurred(FailedToStart).
if (processState == QProcess::Starting) {
if (!_q_startupNotification())
return true;
@@ -2071,10 +2080,10 @@ QByteArray QProcess::readAllStandardError()
The QProcess object will immediately enter the Starting state. If the
process starts successfully, QProcess will emit started(); otherwise,
- error() will be emitted.
+ errorOccurred() will be emitted.
\note Processes are started asynchronously, which means the started()
- and error() signals may be delayed. Call waitForStarted() to make
+ and errorOccurred() signals may be delayed. Call waitForStarted() to make
sure the process has started (or has failed to start) and those signals
have been emitted.
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h
index 81b3ac81d0..21421e1184 100644
--- a/src/corelib/io/qprocess.h
+++ b/src/corelib/io/qprocess.h
@@ -240,7 +240,10 @@ Q_SIGNALS:
void started(QPrivateSignal);
void finished(int exitCode); // ### Qt 6: merge the two signals with a default value
void finished(int exitCode, QProcess::ExitStatus exitStatus);
- void error(QProcess::ProcessError error);
+#if QT_DEPRECATED_SINCE(5,6)
+ QT_MOC_COMPAT void error(QProcess::ProcessError error);
+#endif
+ void errorOccurred(QProcess::ProcessError error);
void stateChanged(QProcess::ProcessState state, QPrivateSignal);
void readyReadStandardOutput(QPrivateSignal);
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 0c65ceb0eb..4a166c540e 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -355,11 +355,13 @@ void tst_QProcess::crashTest()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
- QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
- QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
+ QSignalSpy spy(process, &QProcess::errorOccurred);
+ QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy spy3(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(spy.isValid());
QVERIFY(spy2.isValid());
+ QVERIFY(spy3.isValid());
QVERIFY(process->waitForFinished(30000));
@@ -367,7 +369,10 @@ void tst_QProcess::crashTest()
QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed);
QCOMPARE(spy2.count(), 1);
- QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit);
+ QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed);
+
+ QCOMPARE(spy3.count(), 1);
+ QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy3.at(0).at(1).constData()), QProcess::CrashExit);
QCOMPARE(process->exitStatus(), QProcess::CrashExit);
@@ -390,7 +395,7 @@ void tst_QProcess::crashTest2()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
- QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::errorOccurred));
QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(spy.isValid());
@@ -681,8 +686,10 @@ void tst_QProcess::readTimeoutAndThenCrash()
QCOMPARE(process->error(), QProcess::Timedout);
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
- QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy spy(process, &QProcess::errorOccurred);
+ QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QVERIFY(spy.isValid());
+ QVERIFY(spy2.isValid());
process->kill();
@@ -691,6 +698,8 @@ void tst_QProcess::readTimeoutAndThenCrash()
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed);
+ QCOMPARE(spy2.count(), 1);
+ QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed);
delete process;
process = 0;
@@ -1549,12 +1558,14 @@ void tst_QProcess::failToStart()
QProcess process;
QSignalSpy stateSpy(&process, &QProcess::stateChanged);
- QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
+ QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(stateSpy.isValid());
QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.isValid());
QVERIFY(finishedSpy2.isValid());
@@ -1571,6 +1582,7 @@ void tst_QProcess::failToStart()
for (int j = 0; j < 8; ++j) {
for (int i = 0; i < attempts; ++i) {
QCOMPARE(errorSpy.count(), j * attempts + i);
+ QCOMPARE(errorSpy2.count(), j * attempts + i);
process.start("/blurp");
switch (j) {
@@ -1595,6 +1607,7 @@ void tst_QProcess::failToStart()
QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), j * attempts + i + 1);
+ QCOMPARE(errorSpy2.count(), j * attempts + i + 1);
QCOMPARE(finishedSpy.count(), 0);
QCOMPARE(finishedSpy2.count(), 0);
@@ -1618,11 +1631,13 @@ void tst_QProcess::failToStartWithWait()
QProcess process;
QEventLoop loop;
- QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
+ QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.isValid());
QVERIFY(finishedSpy2.isValid());
@@ -1632,6 +1647,7 @@ void tst_QProcess::failToStartWithWait()
QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), i + 1);
+ QCOMPARE(errorSpy2.count(), i + 1);
QCOMPARE(finishedSpy.count(), 0);
QCOMPARE(finishedSpy2.count(), 0);
}
@@ -1648,16 +1664,18 @@ void tst_QProcess::failToStartWithEventLoop()
QProcess process;
QEventLoop loop;
- QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
+ QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.isValid());
QVERIFY(finishedSpy2.isValid());
// The error signal may be emitted before start() returns
- connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()), Qt::QueuedConnection);
+ connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection);
for (int i = 0; i < 50; ++i) {
@@ -1667,6 +1685,7 @@ void tst_QProcess::failToStartWithEventLoop()
QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), i + 1);
+ QCOMPARE(errorSpy2.count(), i + 1);
QCOMPARE(finishedSpy.count(), 0);
QCOMPARE(finishedSpy2.count(), 0);
}
@@ -1880,11 +1899,13 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess()
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
QProcess process;
- QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
+ QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QSignalSpy finishedSpy1(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
QVERIFY(errorSpy.isValid());
+ QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy1.isValid());
QVERIFY(finishedSpy2.isValid());
@@ -1896,6 +1917,8 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess()
#endif
QCOMPARE(errorSpy.count(), 1);
QCOMPARE(errorSpy.at(0).at(0).toInt(), 0);
+ QCOMPARE(errorSpy2.count(), 1);
+ QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0);
QCOMPARE(finishedSpy1.count(), 0);
QCOMPARE(finishedSpy2.count(), 0);
}
@@ -2221,12 +2244,15 @@ void tst_QProcess::invalidProgramString()
QProcess process;
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
- QSignalSpy spy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
+ QSignalSpy spy(&process, &QProcess::errorOccurred);
+ QSignalSpy spy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
QVERIFY(spy.isValid());
+ QVERIFY(spy2.isValid());
process.start(programString);
QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy2.count(), 1);
QVERIFY(!QProcess::startDetached(programString));
}