PDA

View Full Version : QFile, QTextStream, seek()



TheKedge
29th September 2006, 13:37
Hello all,
sorry if I'm making a silly mistake here, but I'm not sure what the best way is.
I'm making a file that has several blocks (at predefined positions). When I create the file, the blocks are not full (i.e. not contiguous). They will be filled later. So, I'd like to skip/extend the file to the position of the next block. Using a seek() and a write just appends and doesn't work.

how do I extend file?
thanks
K
below is the code:



//make a new file with name in the directory
file = new QFile(path +"\\"+ name);
if(file->open(QIODevice::Append))
fileName = name;// the file has been opened
else
return -1;

// make a text stream
QTextStream stream( file );

// write the header
stream.seek(POS_HEADER);
stream << makeHeader();

// write the comments block
QString comments("This is the standard comments block");
stream.seek( POS_HEADER_COMMENT);
stream << comments;

jacek
29th September 2006, 13:42
open(QIODevice::Append)
Maybe you should use QIODevice::ReadWrite to make seek() work?

TheKedge
29th September 2006, 14:26
I know why you've had more thanks than posts.
thanks
K

wysota
29th September 2006, 15:26
I know why you've had more thanks than posts.

Are you sure he has more thanks than posts? :D

It is true that his thank ratio per thanked post is greater than 1.00 though :)

TheKedge
29th September 2006, 16:07
Ahh, I see,

so he has 359 thanks in 2504 posts ... that's only ...erm, 14% useful posts:p

K