Also add caching for json request
This commit is contained in:
13
main.cpp
13
main.cpp
@@ -6,6 +6,7 @@
|
|||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QSplashScreen>
|
#include <QSplashScreen>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkDiskCache>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "portaudio.h"
|
#include "portaudio.h"
|
||||||
@@ -83,7 +84,17 @@ int main(int argc, char *argv[])
|
|||||||
QEventLoop eventLoop;
|
QEventLoop eventLoop;
|
||||||
|
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
const auto reply = std::unique_ptr<QNetworkReply>(manager.get(QNetworkRequest{QUrl{"https://brunner.ninja/komposthaufen/dpm/presets_config_v12.json"}}));
|
|
||||||
|
QNetworkDiskCache cache;
|
||||||
|
cache.setCacheDirectory("cache");
|
||||||
|
|
||||||
|
manager.setCache(&cache);
|
||||||
|
|
||||||
|
QNetworkRequest request{QUrl{"https://brunner.ninja/komposthaufen/dpm/presets_config_v12.json"}};
|
||||||
|
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||||
|
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, true);
|
||||||
|
|
||||||
|
const auto reply = std::unique_ptr<QNetworkReply>(manager.get(request));
|
||||||
QObject::connect(reply.get(), &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
QObject::connect(reply.get(), &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||||
eventLoop.exec();
|
eventLoop.exec();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user