-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.cpp
More file actions
34 lines (28 loc) · 834 Bytes
/
FileManager.cpp
File metadata and controls
34 lines (28 loc) · 834 Bytes
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 "FileManager.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
FileManager::FileManager(QObject *parent) : QObject(parent) {}
FileManager::~FileManager() {}
QString FileManager::readFile(const QString &path) {
QFile f(path);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Unable to open file for reading:" << path;
return QString();
}
QTextStream in(&f);
QString content = in.readAll();
f.close();
return content;
}
bool FileManager::writeFile(const QString &path, const QString &content) {
QFile f(path);
if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Unable to open file for writing:" << path;
return false;
}
QTextStream out(&f);
out << content;
f.close();
return true;
}