From dc325aab1820029f6f665080fbadfe11a0ff9c7e Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 10 Apr 2012 17:54:22 +0100 Subject: Fix error reporting in QNetworkReplyHttpImplPrivate When errors are detected synchronously in _q_startOperation, they were not reported. This is because unlike the generic QNetworkReplyImpl the function is called directly rather than using a queued connection. In order to report errors, use the _q_error and _q_finished slots so that signals are emitted after returning to the event loop i.e. after the application had a chance to connect the QNetworkReply Change-Id: I8a7bbe79a934f4634fb4e0572ebb5479dfc5f489 Reviewed-by: Lars Knoll Reviewed-by: Martin Petersson --- src/network/access/qnetworkreplyhttpimpl.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 9aabe4f318..fbddd98998 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1529,6 +1529,8 @@ bool QNetworkReplyHttpImplPrivate::start() void QNetworkReplyHttpImplPrivate::_q_startOperation() { + Q_Q(QNetworkReplyHttpImpl); + // ensure this function is only being called once if (state == Working) { qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); @@ -1541,9 +1543,10 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() QSharedPointer session(manager->d_func()->networkSession); QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) { - error(QNetworkReply::BackgroundRequestNotAllowedError, - QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); - finished(); + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::BackgroundRequestNotAllowedError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Background request not allowed."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); return; } #endif @@ -1557,8 +1560,6 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() QNetworkSession *session = managerPrivate->networkSession.data(); if (session) { - Q_Q(QNetworkReplyHttpImpl); - QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)), q, SLOT(_q_networkSessionFailed())); @@ -1566,9 +1567,20 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() session->open(); } else { qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::NetworkSessionFailedError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Network session error."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); + return; } -#endif +#else + qWarning("Backend start failed"); + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::UnknownNetworkError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "backend start error."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); return; +#endif } if (synchronous) { -- cgit v1.2.3