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. QNetworkReply::readAll always returns null, how to get the data downloaded?
Qt 6.11 is out! See what's new in the release blog

QNetworkReply::readAll always returns null, how to get the data downloaded?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I'm trying to download a file:
    @QNetworkRequest request;
    request.setUrl(QUrl(fileUrl));
    QNetworkReply * reply = m_nam.get(request);
    connect(reply, SIGNAL(finished()), this, SLOT(onDownloadRequestFinished()), Qt::UniqueConnection);
    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(onDownloadRequestProgress(qint64, qint64)), Qt::UniqueConnection);@

    And in the onDownloadRequestFinished slot:
    @QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
    if (reply && reply->error() == QNetworkReply::NoError) {
    Q_ASSERT(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200);
    qDebug() << "reply " << reply->bytesAvailable() << reply->pos() << reply->size() << reply->isReadable() << reply->openMode() << reply->isOpen();
    }@

    The slot prints the following: "reply 0 0 0 true OpenMode( "ReadOnly" ) true". So, no data. However, I can clearly see that it does download something somewhere. It's a big file and it does download it, judging from onDownloadRequestProgress (the time it takes and the calculated speed matches the file size and my internet connection speed perfectly).

    Where's the data?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      M Tims
      wrote on last edited by
      #2

      Try connecting the QNetworkReply::readyRead() signal to a slot and read the data there.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vincent007
        wrote on last edited by
        #3

        Did you try examples\network\download ?
        Try it if you did not try.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #4

          I will. Is there anything wrong with my approach?
          By the way, a very important note: the code snippet from my question works in some parts of my project! But not the others. Exactly the same algorithm.

          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