Как установить json стиль для окна mainwindow используя библиотеку nlohmann/json

Рейтинг: 0Ответов: 0Опубликовано: 10.05.2023

Всем привет, хочу задать json style для своего приложения в qt 6.6.0 cmake на языке c++.

#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <fstream>
#include <QMessageBox>
using json = nlohmann::json;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);

    std::ifstream f(":/json/styles/Res/json/styles.json");
    json data = json::parse(f);
    qApp->setStyleSheet(QString::fromStdString(data["style"].get<std::string>()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

При попытке запуска проекта библиотека выдаёт следующую ошибку: terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::parse_error' what(): [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal

styles.json следующий:

{
  "QMainWindow": [
    {
      "title": "MyMarketplace",
      "icon": ":/ico/custom/Res/iconscustom/MyMPico.ico",
      "frameless": true,
      "transluscentBg": true,
      "sizeGrip": "sizeGrip",
      "navigation": [
        {
          "minimize": "pushButtonMinimize",
          "close": "pushButtonExit",
          "restore": [
            {
              "buttonName": "pushButtonRestore",
              "normalIcon": ":/ico/menu/black/Res/iconspack/square.svg",
              "maximizedIcon": ":/ico/menu/black/Res/iconspack/copy.svg"
            }
          ],
          "moveWindow": "headerContainer",
          "tittleBar": "headerContainer"
        }
      ]
    }
  ]
}

Подскажите как исправить ошибку пожалуйста, спасибо

Ответы

Ответов пока нет.