summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2024-08-11 20:54:39 +0200
committerOrangerot <purple@orangerot.dev>2024-08-11 20:54:39 +0200
commitefeec3b99e02fd17fc1c69a0f221d578ccc48eef (patch)
treec38e48e6395c0542424ab773a43a38b9d7f9786c /main.cpp
parentcf013eb832f323cb9de6b114038233b77d115bc8 (diff)
feat(JSON): test QJsonModelorangerot/qjsonmodel-treeview
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/main.cpp b/main.cpp
index aa833f5..134229b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,6 +19,7 @@
// console output
#include <QDebug>
+#include <qlogging.h>
// #include <iostream>
#include "QJsonModel.hpp"
@@ -38,12 +39,12 @@ int main(int argc, char *argv[])
"Item 4"
};
- objectContext->setContextProperty("sports", QVariant::fromValue(dataList));
+ //objectContext->setContextProperty("sports", QVariant::fromValue(dataList));
- QQmlComponent component(&engine, "application.qml");
- QObject *object = component.create(objectContext);
- QObject *eventsList = object->findChild<QObject*>("eventsList");
- QQmlContext *componentContext = component.creationContext();
+ //QQmlComponent component(&engine, "application.qml");
+ //QObject *object = component.create(objectContext);
+ // QObject *eventsList = object->findChild<QObject*>("eventsList");
+ // QQmlContext *componentContext = component.creationContext();
// ... delete object and objectContext when necessary
@@ -70,12 +71,21 @@ int main(int argc, char *argv[])
//parse json
// qDebug() << "Response:" << strReply;
-
- QJsonModel * model = new QJsonModel(strReply.toUtf8());
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
QJsonObject jsonObj = jsonResponse.object();
+ QJsonModel * model = new QJsonModel();
+ // qDebug() << QJsonDocument(jsonObj["units"].toArray()).toJson();
+ // model->loadJson(QJsonDocument(jsonObj["units"].toArray()).toJson());
+ model->loadJson(strReply.toUtf8());
+
+ objectContext->setContextProperty("sports", QVariant::fromValue(model));
// componentContext->setContextProperty("sports", model);
+
+ // objectContext->setContextProperty("sports", QVariant::fromValue(dataList));
+
+ QQmlComponent component(&engine, "application.qml");
+ QObject *object = component.create(objectContext);
qDebug() << "Competitor:" << jsonObj["units"][0]["competitors"][0]["name"].toString();