diff options
author | Orangerot <purple@orangerot.dev> | 2024-08-04 04:50:11 +0200 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-08-04 04:50:11 +0200 |
commit | cf013eb832f323cb9de6b114038233b77d115bc8 (patch) | |
tree | 91481cc6be6d8622dbeffaabcda42500574b393a /main.cpp | |
parent | 71aee728b7bc5868e1e6ade8fbe615a6fdf132ba (diff) |
feat(QJsonModel): compile and first model test
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -21,6 +21,8 @@ #include <QDebug> // #include <iostream> +#include "QJsonModel.hpp" + int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); @@ -28,12 +30,24 @@ int main(int argc, char *argv[]) QQmlEngine engine; QQmlContext *objectContext = new QQmlContext(engine.rootContext()); + + QStringList dataList = { + "Item 1", + "Item 2", + "Item 3", + "Item 4" + }; + + 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(); // ... delete object and objectContext when necessary + // create custom temporary event loop on stack QEventLoop eventLoop; @@ -53,12 +67,16 @@ int main(int argc, char *argv[]) QString strReply = (QString)reply->readAll(); + //parse json // qDebug() << "Response:" << strReply; - QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); + QJsonModel * model = new QJsonModel(strReply.toUtf8()); + QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); QJsonObject jsonObj = jsonResponse.object(); + // componentContext->setContextProperty("sports", model); + qDebug() << "Competitor:" << jsonObj["units"][0]["competitors"][0]["name"].toString(); delete reply; |