PDA

View Full Version : QFile resized files gets truncated after writing



MaximA
23rd May 2008, 18:22
Hi ppl,

I wrote some code to generate a file with a specific size, in which I later put QByteArrays at specific positions (random-acces).

...
file.resize(1024000);
...
file.seek(12335);
pos = file.pos();
c_size=file.write(ba);
pos2 = file.pos();
file.close();
...
//QT4.3 / mingw / windows xp

the initial QFile::resize works
pos and pos2 indicate the right position

after closing the file it is truncated

Any help/idea is highly appreciated, after having exhausted my resources.
Thanks in advance

MaximA
24th May 2008, 18:23
I solved the problem:

instead of

file.open(QIODevice::WriteOnly)
I have to use

file.open(QIODevice::WriteOnly | QIODevice::ReadOnly)
to avoid the truncation