-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVenusReadJson.cpp
executable file
·63 lines (49 loc) · 1.54 KB
/
VenusReadJson.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "VenusReadJson.h"
#include <QDateTime>
#include <QStringList>
#include <QFile>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QVariantMap>
#include <QJsonObject>
#include <QDebug>
//RthDisplayImageViewTool ( RthMainImageDisplay parent)
RTHLOGGER_CREATE_PREFIX("VenusDisplay", VenusReadJson)
RTHDISPLAYIMAGEVIEWTOOL_SCRIPTCONSTRUCTOR(readJsonConstructor, VenusReadJson)
VenusReadJson::VenusReadJson(RthMainImageDisplay *parent)
: RthDisplayImageViewTool(parent) {
}
VenusReadJson::~VenusReadJson()
{
}
bool VenusReadJson::readJsonFile(const QString& filename) {
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Failed to open file:" << filename;
return false;
}
QByteArray jsonData = file.readAll();
file.close();
QJsonParseError error;
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonData, &error);
if (jsonDocument.isNull() || error.error != QJsonParseError::NoError) {
qDebug() << "Failed to parse JSON file:" << filename;
return false;
}
this->jsonData = jsonDocument.object();
return true;
}
bool VenusReadJson::writeJsonFile(const QString& filename) {
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "Failed to create file:" << filename;
return false;
}
QJsonDocument jsonDocument(this->jsonData.toObject());
file.write(jsonDocument.toJson());
file.close();
return true;
}
const QJsonValue& VenusReadJson::getJsonData() const {
return jsonData;
}