-
Notifications
You must be signed in to change notification settings - Fork 0
/
httprequester.cpp
44 lines (33 loc) · 1.18 KB
/
httprequester.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
#include "httprequester.h"
HttpRequester::HttpRequester(QObject *parent) : QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(getReply(QNetworkReply*)));
}
void HttpRequester::get(QString url)
{
QNetworkReply * reply = manager->get(QNetworkRequest(QUrl(url)));
}
void HttpRequester::clearVideos()
{
videos.clear();
}
QList<QObject *> HttpRequester::getVideos()
{
return videos;
}
void HttpRequester::getReply(QNetworkReply *reply)
{
jsonReply = QJsonDocument::fromJson(reply->readAll());
QJsonObject mainObj = jsonReply.object();
QJsonArray itemsArray = mainObj.value("items").toArray();
foreach (QJsonValue item, itemsArray) {
videos.append(new Video(
item.toObject().value("snippet").toObject().value("thumbnails").toObject().value("high").toObject().value("url").toString(),
item.toObject().value("snippet").toObject().value("title").toString(),
item.toObject().value("id").toObject().value("videoId").toString()));
}
emit listReady();
qDebug() << "End of the request!";
}