在QT中如何将网络图片保存到本地
作者:互联网
1 void saveImage(const QString url) 2 { 3 QNetworkRequest request(url); 4 QNetworkAccessManager *networkManager = new QNetworkAccessManager(); 5 QNetworkReply *reply = networkManager->get(request); 6 QEventLoop eventLoop; 7 QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit())); 8 eventLoop.exec(); 9 if(reply->error() == QNetworkReply::NoError) 10 { 11 auto data = reply->readAll(); 12 auto image = QImage::fromData(data); 13 image.save("E:/test.png"); 14 } 15 else 16 { 17 qDebug() << reply->errorString(); 18 } 19 }
说明:第12,13行通过QImage保存图片数据,也可通过QFile来实现。
标签:QT,auto,image,eventLoop,保存,QNetworkReply,本地,networkManager,reply 来源: https://www.cnblogs.com/yitouniu/p/16585742.html