[Qt-interest] Save in data (image) from QNetworkReply

Paul England pengland at cmt-asia.com
Mon Dec 6 14:59:25 CET 2010


This miraculously seems to work though:

QFile out_file( (*it).second );
if ( out_file.open( QIODevice::WriteOnly ) ) {
    out_file.write( data );
    out_file.close();
}

So, disaster avoided for now.

On 12/06/2010 10:49 PM, Paul England wrote:
> I'm getting various images in the form for a QNetworkReply.
> I've tried a few methods, all of which have caveats. 
>
> QImage::save() requires the JPEG plugin which I've not got set up,
> and doesn't allow for other data types it may not support.  As I'm doing
> no editing of these images, it's not really necessary.
>
> Second try was to use a QDataStream().  It's downloading the images,
> but they are "broken".  Nothing will view them.
>
> Code
>
> void my_dialog::reply_finished( QNetworkReply* reply )
> {
>     // error check
>     QByteArray data    = reply->readAll();
>     QString location    = "/path/to/location";
>
>     QFile out_file( location );
>     out_file.open( QIODevice::WriteOnly );\
>     QDataStream stream( &out_file );
>     stream << data;
>     out_file.close();  
> }
>
> Images are there, but broken. :(
> Am I doing something wrong?
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101206/bb5fcd18/attachment.html 


More information about the Qt-interest-old mailing list