-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
44 lines (33 loc) · 1.04 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "utils.h"
#include <QFile>
#include <QJsonDocument>
#include <QDebug>
#include <QJsonObject>
#include <QFileInfo>
#include <QCoreApplication>
#include <QDir>
Utils::Utils()
{
}
Utils::ErrorOrValue Utils::readJsonToVariant(const QString& filePath)
{
QString val;
QFile file;
QString applicationPath = QCoreApplication::applicationDirPath();
QString configurationAbsolutePath = QDir::cleanPath(applicationPath + QDir::separator() + filePath);
file.setFileName(configurationAbsolutePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
ErrorOrValue errorOrvalue;
errorOrvalue.error = QObject::tr("Cannot open: %1").arg(configurationAbsolutePath);
return errorOrvalue;
}
qDebug() << "Using configuration file:" << configurationAbsolutePath;
val = file.readAll();
file.close();
QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
QVariant variant = d.toVariant();
ErrorOrValue errorOrValue;
errorOrValue.value = variant;
return errorOrValue;
}