C++ (Qt)QByteArray data;QBuffer buf( &data );ExProxyDev dev( &buf );
C++ (Qt)QDataStream &operator>>( QDataStream &s, MyObject &obj ){ s >> obj.data1 >> obj.data2 >> obj.data3;}
C++ (Qt)int main(int argc, char *argv[]){ QCoreApplication app(argc, argv); qint8 a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; try { QFile file( "test.dat" ); if( !file.open( QIODevice::ReadOnly ) ) { qWarning() << "File not found."; return 2; } QByteArray data = file.readAll(); QBuffer buf( &data ); ExProxyDev dev( buf ); dev.open( QIODevice::ReadOnly ); QDataStream in( &dev ); in >> a >> b >> c >> d >> e >> f; qDebug() << in.status(); } catch( std::exception &ex ) { qDebug() << ex.what(); } qDebug() << a << b << c << d << e << f; return 0;}
C++ (Qt)QDataStream &operator>>( QDataStream &s, ObjA &a ){ s >> a.m_intVal >> a.m_strVal; return s;} QDataStream &operator>>( QDataStream &s, ObjB &b ){ s >> b.m_shortVal >> b.m_listVal; return s;} QDataStream &operator>>( QDataStream &s, ObjBig &big ){ s >> big.m_objA >> big.m_objB; return s;} QDataStream &operator>>( QDataStream &s, ObjSuper &super ){ s >> super.m_big1 >> super.m_big2 >> super.m_big3; return s;}
C++ (Qt){ QList<ObjSuper> objs; QFile source( ... ); if( !source.open( ... ) ) { ... } QDataStream s( &source ); for( int i = 0; i < 100500; ++i ) { ObjSuper tmp; s >> tmp; if( s.status() ) { // ААаааааа. Ошибка чтения } objs.append( tmp ); }}
C++ (Qt){ QList<ObjSuper> objs; try { QFile file( ... ); ExProxyDev source( file ); source.open( ... ); QDataStream s( &source ); for( int i = 0; i < 100500; ++i ) { ObjSuper tmp; s >> tmp; objs.append( tmp ); } } catch( FileError &err ) { qDebug() << err.info(); }}