1 Star 1 Fork 0

twlkHyman/qmlJsonProvider

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
geturlimage.cpp 3.36 KB
一键复制 编辑 原始数据 按行查看 历史
#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)));
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/twlkHyman/qmlJsonProvider.git
git@gitee.com:twlkHyman/qmlJsonProvider.git
twlkHyman
qmlJsonProvider
qmlJsonProvider
master

搜索帮助