-
Notifications
You must be signed in to change notification settings - Fork 0
/
softupdate.cpp
66 lines (55 loc) · 2.09 KB
/
softupdate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "softupdate.h"
#include <QDesktopServices>
const QString current_version = "0.5.1_alpha";
softUpdate::softUpdate(QWidget *parent) :QWidget(parent)
{
}
void softUpdate::replyFinished(QNetworkReply *reply)
{
QString str = reply->readAll();//读取接收到的数据
// qDebug() << str;
parse_UpdateJSON(str);
}
void softUpdate::parse_UpdateJSON(QString str)
{
QJsonParseError err_rpt;
QJsonDocument root_Doc = QJsonDocument::fromJson(str.toUtf8(),&err_rpt);//字符串格式化为JSON
if(err_rpt.error != QJsonParseError::NoError)
{
return ;
}
if(root_Doc.isObject())
{
QJsonObject root_Obj = root_Doc.object();
QJsonObject PulseValue = root_Obj.value("dealtypecho").toObject();
QString latestVerison = PulseValue.value("LatestVerison").toString();
QString Url = PulseValue.value("Url").toString();
QString UpdateTime = PulseValue.value("UpdateTime").toString();
QString ReleaseNote = PulseValue.value("ReleaseNote").toString();
if(latestVerison != current_version)
{
QString warningStr = "检测到新版本!\t\t\t\t\t\t\n"
"当前版本号:" + current_version +
"\n最新版本号:" + latestVerison +
"\n更新时间:" + UpdateTime +
"\n更新说明:" + ReleaseNote;
int ret = QMessageBox::warning(0, "检查更新", warningStr, "去下载", "不更新");
if(ret == 0) //点击更新
{
QDesktopServices::openUrl(QUrl(Url));
}
}
}
}
void softUpdate::run()
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));//关联信号和槽
QNetworkRequest quest;
quest.setUrl(QUrl("https://blog.gmero.com/softupdate.json")); //包含最新版本软件的下载地址
quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread ART");
manager->get(quest);
}
softUpdate::~softUpdate()
{
}