PDA

View Full Version : Download image returned from a PHP page



Kayote
14th November 2015, 13:02
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:



QNetworkRequest request(QUrl("http://example.com/image.png"));
manager->get(request);


@slot:



QPixmap image;
image.loadFromData(reply->readAll());

ui->lblPic->setPixmap(image);


Help is appreciated :)

anda_skoa
14th November 2015, 13:55
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,
_

Kayote
14th November 2015, 14:55
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.

anda_skoa
14th November 2015, 15:39
The the reply maybe finish with an error?

Cheers,
_

Kayote
14th November 2015, 16:27
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... :eek: