-
Notifications
You must be signed in to change notification settings - Fork 0
/
getbase.cpp
52 lines (42 loc) · 1.35 KB
/
getbase.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
#include "getbase.h"
GetBase::GetBase(QWidget *parent) : QDialog(parent)
{
}
void GetBase::getBaseHttp()
{
progressDialog = new QProgressDialog(this);
fileHttp = new QFile("Yarn.dat");
fileHttp->open(QIODevice::WriteOnly);
url = "http://91.102.219.74/QtProject/Yarn/Base/Yarn.dat";
//url = "http://91.102.219.74/QtProject/Yarn/Yarn.exe";
reply = http.get(QNetworkRequest(url));
connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
connect(reply,SIGNAL(finished()),this,SLOT(httpDone()));
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,
SLOT(updateDataReadProgress(qint64,qint64)));
connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,
SLOT(updateDataReadProgress(qint64,qint64)));
progressDialog->setLabelText(tr("Downloading DataBase ..."));
progressDialog->setEnabled(true);
progressDialog->exec();
}
void GetBase::httpDone()
{
fileHttp->close();
closeConnection();
}
void GetBase::updateDataReadProgress(qint64 readBytes, qint64 totalBytes)
{
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(readBytes);
}
void GetBase::httpReadyRead()
{
if(fileHttp)
fileHttp->write(reply->readAll());
}
void GetBase::closeConnection()
{
progressDialog->hide();
http.destroyed();
}