Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QNetworkAccessManager GET request emits finished signal without start downloading the file



  • We are developing a Qt5 webkit application which loads html5\javascript\css3 pages. Trying to download a file of size 3MB. So created HTTP GET request using QNetworkAccessManager::get() method. But finished signal is emitted immediately with empty data on QNetworkReply::readAll() and there is no network error reported.

    This is reported on Windows 7 and Mac 10.9 with Qt 5.2.0 source code build.
    Here is sample code:

    startDownload:

    @ NetworkRequest request(url);
    QNetworkReply reply = mNetworkManager->get(request);
    QObject::connect(mNetworkManager,SIGNAL(finished(QNetworkReply
    )),this, SLOT(downloadFinished(QNetworkReply*)));@

    In downloadFinished slot:
    @if (reply->error() != QNetwrkReply::NoError){
    qDebug()<<"download is failed"<< reply->errorString()
    }
    else {
    QFile file(location);
    if(file.open(QIODevice::WriteOnly)) {
    file.write(reply->readAll());
    }
    }
    reply->deleteLater();@

    So I would like to know the possibilities of this failure and potential fixes. I don't have much information on this as i couldn't reproduce the issue. Only few of our customers reported the issue.

    Please let me know if any further information needed on the same.

    Thanks in advance.

    Best Regards,
    Pratap



  • HTTPS URL and no OpenSSL libraries installed?
    Proxy required?



  • Hi,

    I don't have much experience with QNAM but looking at the "NetworkError enum values":http://doc.qt.io/qt-5/qnetworkreply.html#NetworkError-enum that can be returned by QNetworkReply::error(), there is a note saying that NoError is reported when a redirect is necessary. Maybe you shold look into that.



  • Thank you very much for the response.. I believe this could be one of the possibilities since QNAM emits the replyFinished signal with out even start downloading. Please let me know if any other possibilities.



  • If a redirect is needed, you should be able to get that information from the network reply itself. We do something like this:

    @
    void FileDownloader::requestFinished()
    {
    QVariant redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    // Check for redirection.
    if (!redirectionTarget.isNull()) {
    m_reply->disconnect(this);
    m_reply->abort();
    m_reply->deleteLater();

        // ...
    
        m_requestUrl = redirectionTarget.toUrl();
    
        start();
        return;
    }
    

    // handle other cases
    }
    @

    Another possiblity is that you are getting an SSL error. Did you also check that? Connect to the sslErrors signal to find out.



  • Thank you very much for the fix. But It was found that the URL which is used to download is a direct URL. So there won't be any chance of redirects.

    I guess QNetworkAccessManager will throw an error QNetworkReply::SslHandshakeFailedError if it is failed with openSSL . We are also building openSSL library and supplying it the application bundle. So I don't think any issue with OpenSSL.

    Thank you.

    [quote author="Andre" date="1421135968"]If a redirect is needed, you should be able to get that information from the network reply itself. We do something like this:

    @
    void FileDownloader::requestFinished()
    {
    QVariant redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    // Check for redirection.
    if (!redirectionTarget.isNull()) {
    m_reply->disconnect(this);
    m_reply->abort();
    m_reply->deleteLater();

        // ...
    
        m_requestUrl = redirectionTarget.toUrl();
    
        start();
        return;
    }
    

    // handle other cases
    }
    @

    Another possiblity is that you are getting an SSL error. Did you also check that? Connect to the sslErrors signal to find out.[/quote]



  • Hi, i have same issue reporeted here:"QNetworkReply readAll() gets empty data on finished()":http://qt-project.org/forums/viewthread/52434/

    [quote author="pratapp123" date="1420805703"]
    This is reported on Windows 7 and Mac 10.9 with Qt 5.2.0 source code build.
    [/quote]

    Where did you read this? It seems to be even in Qt 5.4.0 still unresolved. I have suspected, that on both systems GET is read by some internal service (like RPC server or similar).

    Or did you manage to fix it?


Log in to reply