Results 1 to 5 of 5

Thread: Download image returned from a PHP page

  1. #1
    Join Date
    Nov 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Post Download image returned from a PHP page

    Hi, I am trying to download images so I can show them in a label widget by setting the pixmap.
    My code works fine for images with an url that end with an image file type. However, some of the urls are like this: "http://example.com/image.php" on which the content-type header is set to "image/png" and an image is returned, but my code doesn't work in these cases.

    This is the code:

    Qt Code:
    1. QNetworkRequest request(QUrl("http://example.com/image.png"));
    2. manager->get(request);
    To copy to clipboard, switch view to plain text mode 

    @slot:

    Qt Code:
    1. QPixmap image;
    2. image.loadFromData(reply->readAll());
    3.  
    4. ui->lblPic->setPixmap(image);
    To copy to clipboard, switch view to plain text mode 

    Help is appreciated

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Download image returned from a PHP page

    Have you tried saving the data to a file? Is it a valid PNG file?
    Have you tried passing the image format to load?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Kayote (14th November 2015)

  4. #3
    Join Date
    Nov 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Download image returned from a PHP page

    I tried passing the image format and I saved it to a file, but the file was empty. It seems like the problem is that QNetworkReply doesn't contain any data after the request, I'm not sure why though.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Download image returned from a PHP page

    The the reply maybe finish with an error?

    Cheers,
    _

  6. #5
    Join Date
    Nov 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Download image returned from a PHP page

    Oh god, this was just a stupid on my side. I looked through all the code and I saw I had a reply->readAll() call before reading the image data, which was not supposed to be there. I deleted it and now it works...

Similar Threads

  1. Using QTcpSocket to download image from the web
    By Huk in forum Qt Programming
    Replies: 9
    Last Post: 8th July 2011, 17:49
  2. Download Page Source of Website
    By AjRomano in forum Newbie
    Replies: 3
    Last Post: 11th March 2010, 06:22
  3. download and store/show image
    By peter_hr892h in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 05:16
  4. Download a web page to utf8.
    By Faster in forum Newbie
    Replies: 2
    Last Post: 13th April 2009, 20:49
  5. Download a web page!
    By Faster in forum Newbie
    Replies: 0
    Last Post: 12th April 2009, 13:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.