-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.cpp
34 lines (27 loc) · 897 Bytes
/
Config.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
#include "Config.h"
#include <QFile>
#include <QJsonDocument>
#include <QDebug>
// Singleton: Return the single instance of the Config class
Config& Config::getInstance() {
static Config instance;
return instance;
}
Config::Config() {
configObject = readConfigFile("../config.json");
}
// Method to read the configuration file and return the parsed JSON object
QJsonObject Config::readConfigFile(const QString &filePath) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Could not open config file:" << file.errorString();
return QJsonObject();
}
QByteArray fileData = file.readAll();
file.close();
QJsonDocument jsonDoc(QJsonDocument::fromJson(fileData));
return jsonDoc.object();
}
QJsonObject Config::getConfig() const {
return configObject;
}