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:
// 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();
// 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");
fileData.open(QIODevice::WriteOnly);
QDataStream outData(&fileData);
for (int idx = 0; idx < reports.size(); idx++)
{
// ... more code ...
outData << reports[idx];
}
fileData.flush();
fileData.close();
To copy to clipboard, switch view to plain text mode
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.
QFile fileData
(m_configPath
+ QDir::separator() + "file.dat");
QMultiMap<QString, QString> mmap;
in >> mmap;
qDebug() << mmap;
QFile fileData(m_configPath + QDir::separator() + "file.dat");
fileData.open(QIODevice::ReadOnly);
QDataStream in(&fileData);
QMultiMap<QString, QString> mmap;
in >> mmap;
qDebug() << mmap;
To copy to clipboard, switch view to plain text mode
Can I have a help?
Regards
Bookmarks