1. 程式人生 > >QT顯示url圖片

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