diff options
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; |