Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager GET request emits finished signal without start downloading the file
Qt 6.11 is out! See what's new in the release blog

QNetworkAccessManager GET request emits finished signal without start downloading the file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      HTTPS URL and no OpenSSL libraries installed?
      Proxy required?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckakman
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              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]

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Almer_Cz
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved