QFile file(path + fileName + databaseFormat); if (file.open(QIODevice::WriteOnly)) { QDataStream stream(&file); stream.setVersion(QDataStream::Qt_4_6); stream << studentsList // QList<QString> << marksList //QMultiHash<QString, QHash<int,char> > << themes //QHash<QString> << remind //QHash<QString> << materials; //QHash<QString> if (stream.status() == QDataStream::Ok) return true; } //отправить отчет в ErrorStack // ... #ifdef QT_DEBUG qDebug() << "DataModel::saveDatabase - error"; #endif return false;
C++ (Qt)#include <QtGui> int main(int argc, char* argv[]){ { QList<QString> stringList; QList<int> intList; stringList << "one" << "two"; intList << 1 << 2; QFile f("./out.bin"); if (f.open(QIODevice::WriteOnly)){ QDataStream stream(&f); stream << stringList << intList; if (stream.status() != QDataStream::Ok){ qDebug() << "Write error"; return 1; }else{ qDebug() << "Write successfully complete"; } }else{ qDebug() << "Unable to open file"; return 1; } } // ------------------- { QList<QString> stringList; QList<int> intList; QFile f("./out.bin"); if (f.open(QIODevice::ReadOnly)){ QDataStream stream(&f); stream >> stringList >> intList; if (stream.status() != QDataStream::Ok){ qDebug() << "Read error"; return 1; } qDebug() << "-------"; qDebug() << "stringList:\n" << stringList; qDebug() << "intList:\n" << intList; }else{ qDebug() << "Unable to open file"; return 1; } } return 0;}
QMultiHash<QString, QHash<unsigned int, unsigned char> > *marksList;//...marksList = new QMultiHash<QString, QHash<unsigned int, unsigned char> >();
QDataStream stream(&file); stream.setVersion(QDataStream::Qt_4_6); stream << *marksList;