struct MapPoint{ quint16 code; qint16 lat; qint16 lon;};
QFile f(fileName); if(!f.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, "Error!", "Can not open " + fileName); return false; } quint64 poinCount = f.size() / (sizeof(quint16) + sizeof(qint16) * 2); mapPoints = new QVector<MapPoint>; mapPoints->resize(poinCount); QDataStream in(&f); int i = 0; MapPoint m; while (!in.atEnd()) { in >> m.code >> m.lat >> m.lon; mapPoints->append(m); i++; }
QDataStream in(&f);in >> mapPoints;
C++ (Qt) QFile file(fileName); if(!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, "Error!", "Can not open " + fileName); return false; } QVector<MapPoint> mapPoints; QDataStream in(&file); in >> mapPoints;
C++ (Qt)QDataStream &operator<<(QDataStream & out, const MapPoint &mp) { out << mp.code << mp.lat << mp.lon; return out;} QDataStream &operator>>(QDataStream & in, MapPoint &mp) { in >> mp.code >> mp.lat >> mp.lon; return in;}
C++ (Qt)QByteArray buffer = file.readAll();MapPoint point = *reinterpret_cast<MapPoint*>(buffer.mid(startpos, length).data());
QByteArray buffer = file.readAll();MapPoint point = *reinterpret_cast<MapPoint*>(buffer.mid(startpos, length).data());