-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookwriter.cpp
33 lines (29 loc) · 990 Bytes
/
bookwriter.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
#include "bookwriter.h"
#include <QMetaProperty>
#include <QVariant>
BookWriter::BookWriter() {
fileName.clear();
}
QString BookWriter::write(Book *b) {
const QMetaObject *mObject = b->metaObject();
//Access property
int index = mObject->indexOfProperty("binding");
qDebug() << "indexOfProperty 'binding': " + QString::number(index);
QMetaProperty mProperty = mObject->property(index);
QMetaObject::invokeMethod(b, "write"); //sets the binding
//b->write();
QVariant variant = mProperty.read(b);
qDebug() << variant.toString();
fileName = QFileDialog::getOpenFileName(&widget,("Open file"),"",("(*.xml);(*.txt)"));
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly)) {
qDebug() << "Could not open file";
} else {
QTextStream stream(&file);
stream << variant.toString();
//stream << b->getBinding();
file.close();
qDebug() << "Close file";
}
return b->getBinding();
}