-
Notifications
You must be signed in to change notification settings - Fork 1
/
sender.cpp
43 lines (34 loc) · 1.12 KB
/
sender.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
#include "sender.h"
Sender::Sender(QString cityId,QObject *parent) :
QObject(parent),CityId(cityId)
{
num = 0;
realweather_str = "http://www.weather.com.cn/data/cityinfo/";
realweather2_str = "http://www.weather.com.cn/data/sk/";
moreweather_str = "http://www.weather.com.cn/data/zs/";
Manager = new QNetworkAccessManager;
connect(Manager,SIGNAL(finished(QNetworkReply*)),
this,SLOT(receiveData(QNetworkReply*)));
connect(this,SIGNAL(receiveFinish(int)),this,SLOT(continueSend(int)));
}
void Sender::Send()
{
QString str_1 = realweather_str + CityId +".html";
Manager->get(QNetworkRequest(QUrl(str_1)));
}
void Sender::receiveData(QNetworkReply *reply)
{
messageArray.append(reply->readAll());
emit receiveFinish(++num);
}
void Sender::continueSend(int n)
{
if(n == 1){
QString str_2 =realweather2_str + CityId +".html";
Manager->get(QNetworkRequest(QUrl(str_2)));
} else if(n == 2) {
QString str_more = moreweather_str + CityId + ".html";
Manager->get(QNetworkRequest(QUrl(str_more)));
} else
emit sendData(messageArray);
}