Results 1 to 5 of 5

Thread: QFile - file read parts of the buffer

  1. #1
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QFile - file read parts of the buffer



    All greetings! I would be very grateful if someone show you in my question ...

    I am writing a program backup file, it already works, but only with small files.

    To work with large files, you must read fail parts, but not completely, that would not take much memory...

    Qt Code:
    1. ...
    2. QFile fileRead(filename);
    3.  
    4. const int pageSize = getpagesize();
    5. const int fileSize = fileRead.size();
    6.  
    7. int parts = fileSize/pageSize;
    8. if (fileSize%pageSize != 0)
    9. parts++;
    10.  
    11. buffer = new char[pageSize];
    12.  
    13. for (int partsCount = 0; partsCount < parts; partsCount++) {
    14. //fileRead.read(buffer, fileSize); // ???
    15. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by eugen_Qt; 7th November 2009 at 22:16.

  2. #2
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile - file read parts of the buffer

    How about this?
    Qt Code:
    1. while (!fileRead.atEnd()) {
    2. b += f.readLine();
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile - file read parts of the buffer

    Thanks! that responded...)

    this will work - provided that the string will not be too long ... and if the string is too long?
    or the turnover is too short - the buffer will be a little?

    in any case be restricted with the size of buffer, in this case a buffer size equal to the page (since downloading a file produced by paging)...

    function "getpagesize ()" returns the page size ...

    ie how to read the back fail bytes - for example from the middle of the file?
    Last edited by eugen_Qt; 7th November 2009 at 22:59.

  4. #4
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile - file read parts of the buffer

    If you want to read the file from the middle then:
    Qt Code:
    1. QFile f("f.txt");
    2. if (f.open(QFile::ReadOnly)) {
    3. f.seek(f.size() / 2);
    4. while (!f.atEnd()) {
    5. b += f.readLine();
    6. }
    7. f.close();
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to RSX for this useful post:

    eugen_Qt (10th November 2009)

  6. #5
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile - file read parts of the buffer

    Thank you very much for the tip!!!
    Last edited by eugen_Qt; 10th November 2009 at 15:01.

Similar Threads

  1. Replies: 5
    Last Post: 27th May 2009, 12:49
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24
  4. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43
  5. How to read text only as it is from file
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 08:47

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.