Results 1 to 7 of 7

Thread: Can't read large file (2.5GB) with QFile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Can't read large file (2.5GB) with QFile

    QIODevice::readLine() and QIODevice::readAll() return QByteArrays not QStrings. The QString is being constructed using the conversion constructor, which uses QString::fromAscii(). Depending on the current codec if the first byte of the file is not valid, e.g. a UTF-8 byte-order-mark, then you may well end up with an empty string.

    So, what does you file actually contain, and is it valid characters only?


    ...
    On second thoughts, even if your byte array slurped the entire file into memory, conversion to 16-bit characters in a QString will double the size and blow the 4GB limit on 32-bit architectures.
    Last edited by ChrisW67; 15th July 2011 at 01:49.

  2. #2
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Can't read large file (2.5GB) with QFile

    Yeah, I'm guessing he's out of storage, one way or another.

  3. #3
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Can't read large file (2.5GB) with QFile

    I am on a 64-bit RHEL5 system

    The file is all text.

    Upon further examination, readLine() does work. the first line in the file is blank, if I read the second line, I could see the text. Although this seems to get stuck once the program hits 1.0gb of resident memory usage.

    readAll() just seems to give up and not even try. I looked into it more closely and it looks like it fails to resize the QByteArray to 2.5gb. I would have expected an error but I guess that makes sense.
    I've got 12GB ram on this system.
    Last edited by enricong; 15th July 2011 at 14:27.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Can't read large file (2.5GB) with QFile

    What is the output of 'ulimit -a'? And what context does your code occur in - main() or within a function?

Similar Threads

  1. Read and Write file to/from QFile
    By ruben.rodrigues in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2011, 14:57
  2. QFile - file read parts of the buffer
    By eugen_Qt in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 14:52
  3. Replies: 5
    Last Post: 27th May 2009, 12:49
  4. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24

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
  •  
Qt is a trademark of The Qt Company.