C++ (Qt)
QDataStream ds( &file );
while ( !ds.atEnd() )
{
QTreeWidgetItem * item = new QTreeWidgetItem;
item->read( ds );
if ( ds.status() != QDataStream::Ok )
{
delete item;
break;
}
treeWidget->addTopLevelItem( item );
}
if ( ds.status() != QDataStream::Ok )
{
if ( ds.status() == QDataStream::ReadPastEnd )
qDebug() << "file truncated";
if ( ds.status() == QDataStream::ReadCorruptData )
qDebug() << "invalid file";
}