Xandareva
19th December 2009, 09:29
Hello,
I am new user Qt and I have got problem. So, I don't know how to save QMap with structure to file. I will show code.
void Test::saveMap() {
QString fileName = QFileDialog::getSaveFileName(this, trUtf8("Save map to file"), "", trUtf8("Map (*.ttx);;All files (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, trUtf8("Can't to open file."), file.errorString());
return;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_6);
out << map;
}
}
struct DataMap {
QString name;
QString name1;
QString name2;
};
...
QMap<QString, DataMap> map;
QMap is declared as private - it is all ok. If I save QMap without structure (declaration: QMap<QString, QString> map) all is ok, but if I save QMap with structure DataMap, I have got a lot of errors. How does it fix? How to save QMap with structure to file?
Thanks.
Goodbye.
I am new user Qt and I have got problem. So, I don't know how to save QMap with structure to file. I will show code.
void Test::saveMap() {
QString fileName = QFileDialog::getSaveFileName(this, trUtf8("Save map to file"), "", trUtf8("Map (*.ttx);;All files (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, trUtf8("Can't to open file."), file.errorString());
return;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_6);
out << map;
}
}
struct DataMap {
QString name;
QString name1;
QString name2;
};
...
QMap<QString, DataMap> map;
QMap is declared as private - it is all ok. If I save QMap without structure (declaration: QMap<QString, QString> map) all is ok, but if I save QMap with structure DataMap, I have got a lot of errors. How does it fix? How to save QMap with structure to file?
Thanks.
Goodbye.