CCIMXDesktop
 
Loading...
Searching...
No Matches
MyWeatherRequest.h
1#ifndef MYWEATHERREQUEST_H
2#define MYWEATHERREQUEST_H
3
4#include <QNetworkAccessManager>
5#include <QtClassHelperMacros>
6
13struct WeatherResult : public QObject {
14 Q_OBJECT
15public:
20 explicit WeatherResult(QObject* obj = nullptr)
21 : QObject(obj) { }
22
27 virtual void parseJsonString(const QString json) = 0;
28
29signals:
34
39 void error_occurs(QString cached_error_string);
40};
41
47class WeatherRequest : public QObject {
48 Q_OBJECT
49public:
55
60 explicit WeatherRequest(QObject* parent = nullptr);
61
66 void async_request(const char* base_url);
67
72 virtual QUrlQuery compose_request() = 0;
73
74protected:
75 QNetworkAccessManager manager;
76
80 static constexpr const char* private_key = _DEF_WEATHER_PRIVATE_KEY;
81
82signals:
87 void errorOccurs(QNetworkReply* reply);
88
93 void result_available(const QString json);
94
95private slots:
100 void onReplyFinished(QNetworkReply* reply);
101};
102
103#endif // MYWEATHERREQUEST_H
The WeatherRequest class provides the interface to request weather data.
Definition MyWeatherRequest.h:47
void result_available(const QString json)
Emitted when the result is available.
virtual QUrlQuery compose_request()=0
Composes the request parameters.
QNetworkAccessManager manager
The network manager handling requests.
Definition MyWeatherRequest.h:75
Q_DISABLE_COPY(WeatherRequest)
Disables copy constructor and copy assignment. This prevents copying of the WeatherRequest object.
void async_request(const char *base_url)
Sends the request asynchronously.
Definition MyWeatherRequest.cpp:11
static constexpr const char * private_key
Private key for accessing the weather service.
Definition MyWeatherRequest.h:80
void errorOccurs(QNetworkReply *reply)
Emitted when an error occurs in the request.
The WeatherResult class provides the weather result interfaces.
Definition MyWeatherRequest.h:13
WeatherResult(QObject *obj=nullptr)
Constructor for WeatherResult.
Definition MyWeatherRequest.h:20
virtual void parseJsonString(const QString json)=0
Parses the JSON string.
void error_occurs(QString cached_error_string)
Emitted when an error occurs.
void finish_parse()
Emitted when the parsing is finished.