代码拉取完成,页面将自动刷新
#include "geturlimage.h"
#include <QJsonParseError>
#include <QJsonArray>
#include <QJsonObject>
getUrlImage::getUrlImage(QObject *parent) : QObject(parent)
{
m_TagStrImageUrlList.clear();
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
}
void getUrlImage::getImageUrlList(QString string)
{
// qWarning() << val;
QJsonDocument d = QJsonDocument::fromJson(string.toLatin1());
QJsonObject rootObject = d.object();
QJsonValue pngNameJsonValue = rootObject.value(QString("result"));
// qWarning() << pngNameJsonValue.toString();
QJsonValue framesJsonValue = rootObject.value(QString("resultData"));
// qWarning() << framesJsonValue;
if(framesJsonValue.isArray()){
QJsonArray array = framesJsonValue.toArray();
for(int i = 0; i < array.size(); i++)
{
QJsonValue helloArrayValue = array.at(i);
if(helloArrayValue.isObject())
{
QJsonObject rootObject = helloArrayValue.toObject();
qDebug()<<rootObject.value(QString("menuImgName"));
qDebug()<<rootObject.value(QString("menuImgId")).toString();
qDebug()<<rootObject.value(QString("managerId")).toString();
qDebug()<<rootObject.value(QString("floor"));
qDebug()<<rootObject.value(QString("serialNum"));
qDebug()<<rootObject.value(QString("url"));
qDebug()<<"-------------------------";
setImageUrlToList(rootObject.value(QString("floor")).toString(),
rootObject.value(QString("serialNum")).toDouble(),
rootObject.value(QString("url")).toString());
}
}
}
}
void getUrlImage::setImageUrlToList(QString floor,double serialNum,QString url)
{
QString name;
int isubindextemp = 0;
name = "f" + floor + "p" + QString::number(serialNum);
foreach(str_ImageUrl StrImageUrl,m_TagStrImageUrlList)
{
if(StrImageUrl.name == name)
{
isubindextemp = StrImageUrl.subindex;
}
}
str_ImageUrl StrImageUrlTemp;
StrImageUrlTemp.name = name;
StrImageUrlTemp.subindex = isubindextemp + 1;
StrImageUrlTemp.url = url;
m_TagStrImageUrlList.append(StrImageUrlTemp);
}
void getUrlImage::startgetPictureList()
{
m_getImageUrlIndex = 0;
if(m_TagStrImageUrlList.count() > 0)
{
manager->get(QNetworkRequest(QUrl(m_TagStrImageUrlList.at(m_getImageUrlIndex).url)));
}
}
void getUrlImage::replyFinished(QNetworkReply *reply)
{
if(reply->error() == QNetworkReply::NoError)
{
//获取字节流构造 QPixmap 对象
StrImage StrImageTemp;
StrImageTemp.picture.loadFromData(reply->readAll());
StrImageTemp.name = m_TagStrImageUrlList.at(m_getImageUrlIndex).name
+ "s" + QString::number(m_TagStrImageUrlList.at(m_getImageUrlIndex).subindex);
TagStrImageList.append(StrImageTemp);
m_getImageUrlIndex++;
if(m_getImageUrlIndex < m_TagStrImageUrlList.count())
{
manager->get(QNetworkRequest(QUrl(m_TagStrImageUrlList.at(m_getImageUrlIndex).url)));
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。