PDA

View Full Version : How to get an image from a web srever ?



probine
12th January 2007, 15:39
Hi,

I would like to get an image from a web server. The idea is that this image should be buffered , I guess, in a QByteArray.

Is it a class that already does this ?

How could that be implemented ?

camel
12th January 2007, 16:13
Hi,

I would like to get an image from a web server. The idea is that this image should be buffered , I guess, in a QByteArray.

Is it a class that already does this ?

How could that be implemented ?

Where are you stuck?

Try to combine the approaches of my answers here (http://www.qtcentre.org/forum/p-qhttp-signals-dont-work--post26726/postcount8.html) and here (http://www.qtcentre.org/forum/p-how-to-display-images-in-qtextbrowser--post26781/postcount2.html)?

If you know (a little bit) in advance which images you need:
1) Download them from a server
2) Create the QIimages from the bytearrays, for example via the QImage::fromData ([URL="http://doc.trolltech.com/4.2/qimage.html#fromData-2)
3) Insert the image into an QMap<QString, QImage> using whatever key you need
4) overload the QTextBrowser::loadResource (http://doc.trolltech.com/4.2/qtextbrowser.html#loadResource) function, for example by creating a new scheme "myPics://key"
5) use the image

probine
12th January 2007, 18:12
No, that is not what I want.

I want to be able to get different images who are not predefined.

for example, I want to get an image from www.google.com, tomorrow an other one from somewhere else... and so on.

So I need a class that does this.

camel
12th January 2007, 18:59
for example, I want to get an image from www.google.com, tomorrow an other one from somewhere else... and so on.


Yes, download them via qhttp, put them into the map, use them.

With the little advance knowledge, I mean:
Having the time to wait for qhttp to receive the image, since you have to use the asynchronous qhttp api which, I do believe, would not work directly from loadResource...but you might want to try that out.

(You might also want to try to check out what happens if the, the first time that loadResource is called you return a temp image, then start the download process, and from then on return the right image. But this might be completely undefined behaviour..)

So I would say QHttp is the class you want...minus the cache stuff...which should not be too hard to build