Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QNetworkAccessManager GET request emits finished signal without start downloading the file

    General and Desktop
    5
    7
    2612
    Loading More Posts
    • 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.
    • P
      pratapp123 last edited by

      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 Reply Quote 0
      • C
        ChrisW67 last edited by

        HTTPS URL and no OpenSSL libraries installed?
        Proxy required?

        1 Reply Last reply Reply Quote 0
        • C
          ckakman last edited by

          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 Reply Quote 0
          • P
            pratapp123 last edited by

            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 Reply Quote 0
            • A
              andre last edited by

              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 Reply Quote 0
              • P
                pratapp123 last edited by

                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 Reply Quote 0
                • A
                  Almer_Cz last edited by

                  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 Reply Quote 0
                  • First post
                    Last post