PDA

View Full Version : QTextStream loses position while reading file



bjh
12th February 2008, 22:02
Hi All,

I am opening a QTextStream to read one of a few sizeable text files (5MB - 80MB). The format of the file is about 30 lines of header info I can ignore, then many sets of 13 lines. I want to process all lines of the set of 13 together, then after a delay of about 100 mSec process the next group of 13, etc.

A few times, I have been able to do this successfully for the entire file. But most of the time, after processing some number of sets of 13, the reading of 13 gets out of synch and goes back to somewhere in the header portion of the file that I already read and ignored, and I'm reading something like 3 lines from one group, and 10 lines from the next group, then 6 lines from one group and 7 from another, etc.

I am using readLine() with an argument of zero, which means that any size line can be read. The lines vary from 84 bytes to 275 bytes. The first line of the set of 13 that are read are echoed to the console (printf), which is how I can see that things are getting out of synch. If I change my 100 mSec delay to 200 mSec, the same problem occurs. If I change the delay to 333 mSec, the problem appears to be minimized.

Having said all of that, I'm wondering if: (a) the printfs that I am using are taking up too much time; (b) readLine() itself is slow, and trying to do 13 of them in 100 mSec is not reasonable; or (c) any ideas other than the two just mentioned?

Any thoughts or suggestions? THANKS!


bjh

marcel
12th February 2008, 22:07
How about posting the relevant code?
And why you have to enforce a delay? You could read the file in chunks in a loop and process the line groups on the fly...

bjh
13th February 2008, 15:47
Hi Marcel,

Thanks for the reply!

The 100 mSec delay is enforced because this application is "replaying" data that was acquired at 10 Hz. I think the files (up to 80 MB) may be too large to process completely and then just replay at 10 Hz, so I opted to try and process a chunk of data every 10 Hz.

Relevant code has been attached. It includes the snippet that reads past the header, the method called by the timer loop, and the methods called by the timer-based method. I think that is all that is relevant... :D


bjh