Serialize and read a QVector<QMultiMap<QString, QString>> to a QDataStream
Hi community,
I need to serialize a vector of multi maps to a data stream and read it back.
I did this to write it:
Code:
// Retrieve the model from mainwindow
SelectedListModel *model = reinterpret_cast<SelectedListModel*>(ui->selectedItemsView->model());
// Get the reports data
QVector<QMultiMap<QString, QString>> reports = model->reports();
QFile fileData
(m_configPath
+ QDir::separator() + "file.dat");
for (int idx = 0; idx < reports.size(); idx++)
{
// ... more code ...
outData << reports[idx];
}
fileData.flush();
fileData.close();
Now I have some problem in reading it back from the file.
When I try to read it, it does not read the full data.
Code:
QFile fileData
(m_configPath
+ QDir::separator() + "file.dat");
QMultiMap<QString, QString> mmap;
in >> mmap;
qDebug() << mmap;
Can I have a help?
Regards
Re: Serialize and read a QVector<QMultiMap<QString, QString>> to a QDataStream
Quote:
Can I have a help?
You are not performing reciprocal operations when saving and restoring the multimap. If you want to read it using in >> map, then you must save it using out << map. The inherited QMap operator>>() and operator<<() methods will take care of the serialization parts.
Re: Serialize and read a QVector<QMultiMap<QString, QString>> to a QDataStream
You always save my life :)