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. Downloading Image File
Qt 6.11 is out! See what's new in the release blog

Downloading Image File

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.7k 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.
  • S Offline
    S Offline
    SimonJudge
    wrote on last edited by
    #1

    I am trying to download a jpg file...

    @nam = new QNetworkAccessManager(this);
    QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpCompleted(QNetworkReply*)));

    QUrl url("http://mysite.com/test.jpg");
    nam->get(QNetworkRequest(url));@

    In httpCompleted...

    @if (reply->error() == QNetworkReply::NoError)
    {
    QByteArray bytes = reply->readAll();
    int count = bytes.count();

    ... save to file

    }@

    This mechanism works for non-image files but fails for images.
    bytes.count() is zero even though reply->bytesAvailable() is the size of the image file.

    Anyone seen this before?

    Thanks

    Simon

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      you will see from docs that readAll() has no mechanism to return error on failure and returns an empty bytearray. maybe you need to use some other call ...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SimonJudge
        wrote on last edited by
        #3

        Using read() instead returns minus 1. reply->errorString(); is "Unknown error".

        Simon

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deimos
          wrote on last edited by
          #4

          It's possible that no error is returned if a redirection occurred. Try to check content of bytes (qDebug() << bytes) or try to look for a redirection:

          @QString forwardedUrl;
          forwardedUrl= reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl().toString();@

          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