Results 1 to 3 of 3

Thread: QTextStream loses position while reading file

  1. #1
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextStream loses position while reading file

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream loses position while reading file

    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...

  3. #3
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextStream loses position while reading file

    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...


    bjh
    Attached Files Attached Files

Similar Threads

  1. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. Replies: 1
    Last Post: 18th July 2006, 12:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.