QT显示url图片

QT 显示网络图片我目前的办法就是先下载下来 然后显示  如果有好的办法请相互交流一下

需要调用的头文件

#include <QNetworkAccessManager>
#include <QNetworkReply>

需要在工程中添加

QT += network

主要的代码:

#include "dialog.h"
#include "ui_dialog.h" Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this); connect(&netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); QUrl url;
url = QUrl("http://kexirobot.oss-cn-shanghai.aliyuncs.com/upload/robot0/pic1/1.png");
QNetworkRequest request;
request.setUrl(url);
netManager.get(request);
}
void Dialog::replyFinished(QNetworkReply *reply)
{
qDebug() << "reply :" << reply<< endl; if(reply->error() == QNetworkReply::NoError)
{
QByteArray data_bytes = reply->readAll();
QPixmap* cur_pictrue =new QPixmap();
cur_pictrue->loadFromData(data_bytes);
cur_pictrue->save("./cur_night_picture.png");
// delete cur_pictrue;
// picture[1].load("cur_night_picture.png");
}
reply->deleteLater(); } Dialog::~Dialog()
{
delete ui;
} 工程代码
https://pan.baidu.com/s/1JgEbJH-QNW_T3ECmmI5EkQ

 
上一篇:转载--tomcat调优


下一篇:iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明