QNetworkReplyFileImpl: Don't emit 'finished' in the ctor

Fixes: QTBUG-105618
Change-Id: I3bd36fbd5818d54088098e750643c3e2de30496e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 68f641095c5403925e49954aea0e65c4574121e0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2022-09-15 15:52:43 +02:00 committed by Qt Cherry-pick Bot
parent 7bb095f09c
commit f2c00dd038
2 changed files with 15 additions and 1 deletions

View File

@ -57,9 +57,10 @@ QNetworkReplyFileImpl::QNetworkReplyFileImpl(QNetworkAccessManager *manager, con
// we handle only local files
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString());
setError(QNetworkReply::ProtocolInvalidOperationError, msg);
setFinished(true); // We're finished, will emit finished() after ctor is done.
QMetaObject::invokeMethod(this, "errorOccurred", Qt::QueuedConnection,
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProtocolInvalidOperationError));
fileOpenFinished(false);
QMetaObject::invokeMethod(this, [this](){ fileOpenFinished(false); }, Qt::QueuedConnection);
return;
}
#endif

View File

@ -260,6 +260,7 @@ private Q_SLOTS:
void ioGetFromFileSpecial();
void ioGetFromFile_data();
void ioGetFromFile();
void ioGetFromFileUrl();
void ioGetFromFtp_data();
void ioGetFromFtp();
void ioGetFromFtpWithReuse();
@ -3330,6 +3331,18 @@ void tst_QNetworkReply::ioGetFromFile()
QCOMPARE(reader.data, data);
}
void tst_QNetworkReply::ioGetFromFileUrl()
{
// This immediately fails on non-windows platforms:
QNetworkRequest request(QUrl("file://unc-server/some/path"));
QNetworkReplyPtr reply(manager.get(request));
QSignalSpy finishedSpy(reply.get(), &QNetworkReply::finished);
// QTBUG-105618: This would, on non-Windows platforms, never happen because the signal
// was emitted before the constructor finished, leaving no chance at all to connect to the
// signal
QVERIFY(finishedSpy.wait());
}
void tst_QNetworkReply::ioGetFromFtp_data()
{
if (!ftpSupported)