include QtCore include QtWidgets class Proger QDataStream operator QDa

 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
#include <QtCore>
#include <QtWidgets>
class Proger;
QDataStream& operator>>(QDataStream &in, Proger *p);
class Proger {
public:
int age;
bool canReinstallWindows;
Proger(int age, bool cRW) {
this->age = age;
this->canReinstallWindows = cRW;
}
static void save(Proger *p, QString filename) {
QFile f(filename);
f.open(QIODevice::WriteOnly);
QDataStream out(&f);
out.setVersion(QDataStream::Qt_5_2);
out << p;
f.close();
}
static void load(Proger *p, QString filename) {
QFile f(filename);
f.open(QIODevice::ReadOnly);
QDataStream in(&f);
in.setVersion(QDataStream::Qt_5_2);
in >> p;
f.close();
}
};
QDataStream& operator>>(QDataStream &in, Proger *p) {
in >> p->age >> p->canReinstallWindows;
return in;
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Proger proger(24, true);
Proger::save(&proger, "/etc/dir/file.txt");
return a.exec();
}