Hi,
I am overloading the operator>>() and operator<<() for QDataStream to serialize my own data blocks.
For writing in to binary file:
{
b_data.resize(sizeof(data));
memcpy(b_data.begin(),&data,sizeof(data));
s<<b_data;
return s;
}
QDataStream & operator<<( QDataStream &s, AtmosBBlock &data)
{
QByteArray b_data;
b_data.resize(sizeof(data));
memcpy(b_data.begin(),&data,sizeof(data));
s<<b_data;
return s;
}
To copy to clipboard, switch view to plain text mode
For reading from binary file:
{
b_data.resize(sizeof(data));
s>>b_data;
memcpy(&data,b_data.begin(),sizeof(data));
return s;
}
QDataStream & operator>>( QDataStream &s, AtmosBBlock &data)
{
QByteArray b_data;
b_data.resize(sizeof(data));
s>>b_data;
memcpy(&data,b_data.begin(),sizeof(data));
return s;
}
To copy to clipboard, switch view to plain text mode
The problem is, that s>>b_data is resulting in a 0 sized QByteArray, and I don't understand why.
To check if the problem is in the written file I did the following:
{
b_data.resize(sizeof(data));
s.readRawBytes((char*)&b_data,sizeof(b_data));
memcpy(&data,b_data.begin(),sizeof(data));
return s;
}
QDataStream & operator>>( QDataStream &s, AtmosBBlock &data)
{
QByteArray b_data;
b_data.resize(sizeof(data));
s.readRawBytes((char*)&b_data,sizeof(b_data));
memcpy(&data,b_data.begin(),sizeof(data));
return s;
}
To copy to clipboard, switch view to plain text mode
This reads the file correctly with the previously written data.
Any idea why s>>b_data returns a 0 sized QByteArray?
Thanks in adavance.
Bookmarks