diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-02 10:53:13 +0200 |
---|---|---|
committer | Steru <jerrydream111@gmail.com> | 2024-08-02 10:53:13 +0200 |
commit | ab7280aa471346374520eca3ca8c50742e70510f (patch) | |
tree | cadf81145f3ceac9c577cad27106dd0b7b780251 | |
parent | a507698b6813604c0d547a2e4c5e1cc65c08f93d (diff) | |
parent | ef2b0ced30063654f06bb1ff12ba6f2a86167bc9 (diff) |
Combined CMakeLists.
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/main/main.cpp | 54 |
2 files changed, 60 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 32f072c..d2fbfb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,13 @@ project(itat_challange_olympics) set(CMAKE_CXX_STANDARD 17) add_executable(itat_challange_olympics src/main/main.cpp) +find_package(Qt6 REQUIRED COMPONENTS Core) +target_link_libraries(itat_challange_olympics PRIVATE Qt6::Core) + find_package(Qt6 REQUIRED COMPONENTS Quick) target_link_libraries(itat_challange_olympics PRIVATE Qt6::Quick) +find_package(Qt6 REQUIRED COMPONENTS Network) +target_link_libraries(itat_challange_olympics PRIVATE Qt6::Network) + target_link_libraries(itat_challange_olympics PRIVATE d3d12.lib dxgi.lib d3dcompiler.lib dxguid.lib) diff --git a/src/main/main.cpp b/src/main/main.cpp index 52a6c2d..cddb26b 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -3,6 +3,24 @@ #include <QQmlContext> #include <QQmlComponent> +// networking +#include <QNetworkAccessManager> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QUrl> +#include <QUrlQuery> + +// json parsing +#include <QJsonValue> +#include <QJsonDocument> +#include <QJsonObject> +#include <QVariantMap> +#include <QJsonArray> + +// console output +#include <QDebug> +// #include <iostream> + int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); @@ -15,5 +33,41 @@ int main(int argc, char *argv[]) // ... delete object and objectContext when necessary + + // create custom temporary event loop on stack + QEventLoop eventLoop; + + // "quit()" the event-loop, when the network request "finished()" + QNetworkAccessManager mgr; + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); + + QString endpoint { "https://sph-s-api.olympics.com/summer/schedules/api/ENG/schedule/discipline/ARC" }; + + // the HTTP request + QNetworkRequest req( (QUrl( endpoint )) ); + QNetworkReply *reply = mgr.get(req); + eventLoop.exec(); // blocks stack until "finished()" has been called + + if (reply->error() == QNetworkReply::NoError) { + //success + + QString strReply = (QString)reply->readAll(); + + //parse json + // qDebug() << "Response:" << strReply; + QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); + + QJsonObject jsonObj = jsonResponse.object(); + + qDebug() << "Competitor:" << jsonObj["units"][0]["competitors"][0]["name"].toString(); + + delete reply; + } + else { + //failure + qDebug() << "Failure" <<reply->errorString(); + delete reply; + } + return app.exec(); } |