Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Empty QJsonDocument from file

$
0
0
Hi, I’m trying to parse an appSettigns.json file that holds some application settings, but when I set the json document with QJsonDocument::fromJson(file.readAll()) the json document stays empty. Here’s the code: jsonmanager.cpp #include "jsonmanager.h"   #include <QFile> #include <QDebug> #include <QJsonDocument> #include <QJsonObject>   JsonManager::JsonManager(QWidget *parent) {     QFile file(":/config/appSettings.json");     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {         qDebug() << "Could not open file";         qDebug() << file.errorString();         return;     }       QJsonDocument   jsonDoc;     jsonDoc = QJsonDocument::fromJson(file.readAll());     if (!jsonDoc.isNull()) {         qDebug() << "Could not read data";     }       QJsonObject jsonObj = jsonDoc.object();     QVariantMap jsonMap = jsonObj.toVariantMap();     qDebug() << jsonMap.size();  // outputs 0     // and so does jsonDoc.array().size();       file.close(); } appSettings.json {     "osc_port":57120,     "server": {         "path": "/path/to/executable",         "ip": "127.0.0.1",         "port": 54321     },     "data_path": "/path/to/data/folder",     "frame_rate": 25,     "vertical_sync": true,     "threshold": 64,     "camera": {         "device_id": 0,         "width": 640,         "height": 480,         "rotate_180": false,         "use_uvc": false     },     "background_color": {         "red": 64,         "green": 64,         "blue": 64,         "alpha": 255,     },     "tool_highlight_color": {         "red": 240,         "green": 64,         "blue": 64,         "alpha": 128,     } } I also checked the array in the QJsonDocument but it’s empty, too. Any hints on what I’m doing wrong? Thanks!

Viewing all articles
Browse latest Browse all 13965