Reading a binary file
-
hi to everyone
i am trying to read a binary file and save it to my db as a blob data(qsqlite)
i use this code
@ QFIle myfile("1.zip");
QByteArray x;
if(!myfile.open())
return;
while(!myfile.atEnd())
x = myfile.readall();
QFIle myfile1("1.png");
QByteArray x1;
if(!myfile1.open())
return;
while(!myfile1.atEnd())
x1 = myfile1.readall();
@
i think it only read the a few first charachters of my file
how can i solve this? -
bq. QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings
Behind the scenes, it always ensures that the data is followed by a '\0' terminatorPerhaps this is the reason why you see only part of the array.
-
You're speaking of charactares, which makes me guess that you're on the wrong concept.
You must not print arbitrary binary data with printf() or qDebug()! As cincirin already mentioned, this stops at the first null-byte (0x00) regardless how big your data is.
You must check the byte array's size with x.size().