[Qt-interest] Displaying Image Resources from an URL

Sean Harmer sean.harmer at maps-technology.com
Thu Nov 5 19:06:24 CET 2009


On Thursday 05 Nov 2009 17:27:53 Sean Harmer wrote:
> Hi,
> 
> On Thursday 05 Nov 2009 15:16:37 R. Reucher wrote:
> > On Thu, 05 Nov 2009 14:57:02 +0000, Sean Harmer wrote:
> > >> > image on the server itself and directly link to it from my
> > >> > application without downloading it ?
> > >
> > > How do you hope to display data without downloading it? Something has
> > > to download it.
> >
> > I guess he means not to explicitly store it on disk...
> 
> Who says that you need to store it on disk? QNetworkReply is a QIODevice so
> you can just read from it. No need to store anything to disk at all -
>  unless you want to of course.
> 
> > >> Yes. Just use a QWebView for your images. Which, of course, doesn't
> > >> mean the image won't be downloaded, of course.
> > >
> > > In fact I think this uses QNetworkAccessManager under the bonnet
> > > anyway.
> >
> > Yes, it does. But you can simply use the widget and feed it with the
> > URL... much easier perhaps.
> 
> Possibly, but it is only about 4 lines of code to use QNetworkAccessManager
> and using it in conjunction with a QLabel for e.g. it is much more light
> weight that using an entire QWebView. That is just overkill for simply
> displaying an image.

Please find attached a trivial example of how to use QNetworkAccessManager to 
download an image and show it in a QLabel. I have not done any kind of input 
validation or validation of the downloaded data but it gives you an idea of 
how simple it is to use these classes at least at a basic level.

Have fun,

Sean
-------------- next part --------------
A non-text attachment was scrubbed...
Name: show-remote-image.tar.gz
Type: application/x-compressed-tar
Size: 1875 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091105/7a377ee5/attachment.bin 


More information about the Qt-interest-old mailing list