1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
void ImageDownloader::downloadImg()
{
QNetworkAccessManager *nam;
nam = new QNetworkAccessManager(this);
connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(downloadImg_finished(QNetworkReply*)));
QUrl url = QUrl("http://............./image.gif");
QNetworkRequest requete(url);
QByteArray postData;
QNetworkReply *r = nam->post(requete, postData);
//qDebug();
}
void ImageDownloader::downloadImg_finished(QNetworkReply *reply)
{
reply->open(QIODevice::ReadOnly);
if(reply->error() == QNetworkReply::NoError)
{
QByteArray b = reply->readAll();
QFile file("test.gif"); //avec l'extension
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out<<b;
emit downloadImg_success();
}
else
{
qDebug() << reply->errorString();
}
} |
Partager