qt - QNetworkRequest to download an image? -


i have used qnetworkrequest retrieve xml off web without problems:

request.seturl(qurl("http://api.somesite.com/api/4we35r/somefile.xml"));  mynetworkaccessmanager->get(request); 

how go downloading image? ex:

http://www.mysite.com/27eye28/images/myimage.png 

do replace xml url above png url? have special?

yes, replacing url have do.

here's working example,

void mainwindow::getimage(qstring url) {     qnetworkaccessmanager* manager = new qnetworkaccessmanager(this);     connect(manager, signal(finished(qnetworkreply *)), this, slot(replyfinished(qnetworkreply *)));      qurl url = qurl(url);      qnetworkrequest request(url);      manager->get(request); }  void mainwindow::replyfinished(qnetworkreply *reply) {     if(reply->error() != qnetworkreply::noerror)     {         ui->textbrowser->settext("error: " +  reply->errorstring());     }     else     {         qbytearray responsedata = reply->readall();         qfile file("d:\\myimage.png");         file.open(qiodevice::writeonly);         file.write((responsedata));         file.close();     } } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -