forked from AutumnEarly/QtQuickSimplePlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqctool.cpp
45 lines (36 loc) · 1000 Bytes
/
qctool.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
#include "qctool.h"
QCTool::QCTool()
{
}
void QCTool::writeFile(const QString &filePath, const QString &obj)
{
QFileInfo fileInfo(filePath);
QDir dir = fileInfo.absoluteDir();
if(!dir.exists()) {
dir.mkpath(".");
}
QFile file(filePath);
if(!file.open(QIODevice::WriteOnly)) {
qDebug() << "写入失败";
return;
}
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(obj.toUtf8(),&error);
if (error.error == QJsonParseError::NoError) {
file.write(jsonDoc.toJson());
file.close();
}
// qDebug() << "文件保存地址: "<< fileInfo.absoluteFilePath();
}
QString QCTool::readFile(const QString &filePath)
{
QString obj;
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly)) {
qDebug() << "文件打开失败";
return obj;
}
QByteArray data(file.readAll());
file.close();
return QString(data);
}