-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQMLFileIo.cpp
49 lines (38 loc) · 1.02 KB
/
QMLFileIo.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
#include "QMLFileIo.h"
QMLFileIo::QMLFileIo(QQuickItem *parent):
QQuickItem(parent)
{
// By default, QQuickItem does not draw anything. If you subclass
// QQuickItem to create a visual item, you will need to uncomment the
// following line and re-implement updatePaintNode()
// setFlag(ItemHasContents, true);
}
QMLFileIo::~QMLFileIo()
{
}
void QMLFileIo::setPath(QString path) {
mPath = path;
emit pathChanged(mPath);
}
static void writeToFile(QFile &file, const QString &text) {
QTextStream stream(&file);
stream << text;
}
void QMLFileIo::write(QString text) {
QFile file(mPath);
if (file.open(QIODevice::WriteOnly))
writeToFile(file, text);
file.close();
}
void QMLFileIo::append(QString text) {
QFile file(mPath);
if (file.open(QIODevice::Append))
writeToFile(file, text);
file.close();
}
QString QMLFileIo::readAll() {
QFile file(mPath);
if (file.open(QIODevice::ReadOnly))
return QString::fromUtf8(file.readAll());
return QString();
}