PDA

View Full Version : Size Of QBuffer Not Correct?



justin123
19th April 2011, 22:15
I have a small problem with QBuffer. I'm writing PNGs to it and writing the byte array in my map file using fwrite in this format:

Size
Data

When I read the first image from the map file is says its size is 304, but that is not correct because when I try to read the second image the size reads as zero and the image is never read correctly.

Is 304 not the size of the array in bytes? If so then the image is not being written correctly in first place.

squidge
19th April 2011, 23:07
Post the code you are using

justin123
20th April 2011, 02:10
void Tileset::write( FILE *file)
{
for (int i = 0; i < mTiles.size(); ++i)
{
QByteArray ba;
QBuffer buffer( &ba);
unsigned int size = 0;

buffer.open( QIODevice::WriteOnly);
mTiles[i]->image().save( &buffer, "PNG", -1);
buffer.close();

size = (unsigned int)ba.size();
char *data = new char[size];
data = ba.data();

fwrite( &size, sizeof(unsigned int), 1, file);
fwrite( data, sizeof(char), size, file);
}
}