consistently handle empty program string in QProcess::start overloads
All overloads of QProcess::start will now check whether the program string is empty and in that case - set error to FailedToStart, - set errorString to "No program defined", - emit error. Until now only one of the three overloads behaved like this. As a side effect, start(QString(), QStringList()) will not crash on Windows anymore. Task-number: QTBUG-47404 Change-Id: I2f93657204fe3643b1d74a74817843c05fc4a96b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jake Petroules <jake.petroules@petroules.com> Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
parent
2a38265571
commit
edb5f22b0a
@ -2062,6 +2062,13 @@ void QProcess::start(const QString &program, const QStringList &arguments, OpenM
|
||||
qWarning("QProcess::start: Process is already running");
|
||||
return;
|
||||
}
|
||||
if (program.isEmpty()) {
|
||||
Q_D(QProcess);
|
||||
d->processError = QProcess::FailedToStart;
|
||||
setErrorString(tr("No program defined"));
|
||||
emit error(d->processError);
|
||||
return;
|
||||
}
|
||||
|
||||
d->program = program;
|
||||
d->arguments = arguments;
|
||||
@ -2086,7 +2093,10 @@ void QProcess::start(OpenMode mode)
|
||||
return;
|
||||
}
|
||||
if (d->program.isEmpty()) {
|
||||
qWarning("QProcess::start: program not set");
|
||||
Q_D(QProcess);
|
||||
d->processError = QProcess::FailedToStart;
|
||||
setErrorString(tr("No program defined"));
|
||||
emit error(d->processError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,8 @@ private slots:
|
||||
void failToStart();
|
||||
void failToStartWithWait();
|
||||
void failToStartWithEventLoop();
|
||||
void failToStartEmptyArgs_data();
|
||||
void failToStartEmptyArgs();
|
||||
|
||||
protected slots:
|
||||
void readFromProcess();
|
||||
@ -1672,6 +1674,42 @@ void tst_QProcess::failToStartWithEventLoop()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QProcess::failToStartEmptyArgs_data()
|
||||
{
|
||||
QTest::addColumn<int>("startOverload");
|
||||
QTest::newRow("start(QString, QStringList, OpenMode)") << 0;
|
||||
QTest::newRow("start(QString, OpenMode)") << 1;
|
||||
QTest::newRow("start(OpenMode)") << 2;
|
||||
}
|
||||
|
||||
void tst_QProcess::failToStartEmptyArgs()
|
||||
{
|
||||
QFETCH(int, startOverload);
|
||||
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
|
||||
|
||||
QProcess process;
|
||||
QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error));
|
||||
QVERIFY(errorSpy.isValid());
|
||||
|
||||
switch (startOverload) {
|
||||
case 0:
|
||||
process.start(QString(), QStringList(), QIODevice::ReadWrite);
|
||||
break;
|
||||
case 1:
|
||||
process.start(QString(), QIODevice::ReadWrite);
|
||||
break;
|
||||
case 2:
|
||||
process.start(QIODevice::ReadWrite);
|
||||
break;
|
||||
default:
|
||||
QFAIL("Unhandled QProcess::start overload.");
|
||||
};
|
||||
|
||||
QVERIFY(!process.waitForStarted());
|
||||
QCOMPARE(errorSpy.count(), 1);
|
||||
QCOMPARE(process.error(), QProcess::FailedToStart);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef Q_OS_WINCE
|
||||
// Reading and writing to a process is not supported on Qt/CE
|
||||
|
Loading…
Reference in New Issue
Block a user