-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmfile.cpp
63 lines (54 loc) · 1.52 KB
/
mfile.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 "mfile.h"
MFile::MFile(QObject *parent)
: QFile{parent}
{
}
MFile::MFile(QString name)
: QFile{name}
{
}
bool MFile::read_Content()
{
/* Versuche das File zu öffnen,
* wenn das fehl schlägt gib eine Fehlermeldung raus
* und bende die Funktion mit false */
if(!this->open(QFile::ReadOnly))
{
emit sig_Err("Konnte " + fileName() + " nicht oeffenen");
return false;
}
/* Erzeuge einen QStream auf das File
* Setze die Codierung auf Latin1 */
textStream_Read = new QTextStream(this);
textStream_Read->setAutoDetectUnicode(false);
textStream_Read->setEncoding(QStringConverter::Latin1);
/* Lösche den Inhalt von stringList_Content
* Lese Zeile für Zeile und schreibe jede Zeile in die QStringList stringList_Content
* schliesse das File */
stringList_Content.clear();
while(!textStream_Read->atEnd())
{
stringList_Content.append(textStream_Read->readLine());
//emit sig_Log(stringList_Content.last());
}
this->close();
return true;
}
void MFile::save(QStringList stringList)
{
this->remove();
if(!this->open(QFile::WriteOnly))
{
emit sig_Err("Konnte " + fileName() + " nicht oeffenen");
return;
}
textStream_Write = new QTextStream(this);
textStream_Write->setAutoDetectUnicode(false);
textStream_Write->setEncoding(QStringConverter::Latin1);
foreach(QString str, stringList)
{
*textStream_Write << str << '\n';
}
this->close();
return;
}