Results 1 to 7 of 7

Thread: Read from File :: Help required

  1. #1
    Join Date
    Feb 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows

    Question Read from File :: Help required

    Hi

    I have file containing 1 GB of data. But I have to read only the last 1000 data from the file.
    How can I go for it? Reading the entire file takes more than 15 minutes.

    Thanks for any help.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read from File :: Help required

    Read about QFile::seek and QFile::size

  3. #3
    Join Date
    Feb 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows

    Default Re: Read from File :: Help required

    Quote Originally Posted by Lesiok View Post
    Read about QFile::seek and QFile::size
    Hi Lesiok
    Thanks for your help. But for using these functions I have to first know the number of lines in the file.
    How can I get the number of lines in the file in one command?

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read from File :: Help required

    Lines? 1 GB TextFile??

    Otherwise QFile::size is really all you need.

    If by lines you mean records of a given size, you can seek to QFile::size() - recordsize*1000 ...

    Johannes

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read from File :: Help required

    If lines have non const length the problem is not trivial.

  6. #6
    Join Date
    Feb 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows

    Default Re: Read from File :: Help required

    Quote Originally Posted by Lesiok View Post
    If lines have non const length the problem is not trivial.
    Line sizes varies. Otherwise it would have been simple to multiply number of lines by each line size & subtract it from total file size.

    In such case how can I do it?

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read from File :: Help required

    Only reading all file. I think that it is time to change a philosophy. 1 GB text file it is not good idea.

Similar Threads

  1. is qt phonon can read realmedia file and divx file
    By fayssalqt in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2009, 15:42
  2. How to read a simple xml file.
    By bod in forum Qt Programming
    Replies: 17
    Last Post: 27th June 2008, 09:13
  3. Replies: 1
    Last Post: 20th June 2008, 18:43
  4. Read An Xml File
    By Alienxs in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2007, 00:28
  5. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 1st June 2006, 23:14

Tags for this Thread

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.