———————HTTP获取图片———————
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qnetworkaccessmanager.h"
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
#include "QDebug"
#include "qfile.h"
QNetworkAccessManager *test;
QNetworkReply *reply;
QFile * file;
//关联可读信号
connect(reply, &QIODevice::readyRead, this, &MainWindow::slotReadyRead);
//关联下载信号
connect(reply, &QNetworkReply::downloadProgress, this, &MainWindow::downRepose);
//设置链接
QNetworkRequest request;
request.setUrl(QUrl("http://file.alapi.cn/image/comic/120112-15286032729447.jpg"));
//发起请求
reply = test->get(request);
void MainWindow::slotReadyRead()
{
file->write( reply->readAll() );
}
void MainWindow::downRepose( qint64 bytesReceived, qint64 bytesTotal )
{
qDebug() <<"资源总大小" << bytesTotal << "当前大小" << bytesReceived ;
if( bytesTotal == bytesReceived )
{
file -> close();
QPixmap pic("rlxy.jpg");
pic = pic.scaled( ui->label->size() );
ui->label->setPixmap(pic );
}
}
———————代码获取查看下方———————