Results 1 to 3 of 3

Thread: Large File Processing

  1. #1
    Join Date
    Feb 2011
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Large File Processing

    Hello,
    I would like to know which is the optimized way to append large file content to a small file. I did the following, but it doesn't work for more than a 1 GB file, it throws error, while reading file content during "QByteArray myFileData = fileHandle2.readAll();"

    Qt Code:
    1. QFile fileHandle, fileHandle2;
    2. fileHandle.setFileName("SourceFile.txt");
    3. fileHandle2.setFileName("VectorFile.txt");
    4. if(fileHandle.open(QIODevice::Append|QIODevice::Text))
    5. {
    6. if(fileHandle2.open(QIODevice::ReadOnly|QIODevice::Text))
    7. {
    8. QByteArray myFileData = fileHandle2.readAll();
    9.  
    10. if(myFileData.isEmpty())
    11. QMessageBox::critical(this,"File Operations","File read error...");
    12.  
    13. if(fileHandle.write(myFileData) == -1)
    14. QMessageBox::critical(this,"File Operations","File append error...");
    15. }
    16. }
    17.  
    18. fileHandle.close();
    19. fileHandle2.close();
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Sankar.

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Large File Processing

    QString QTextStream::readAll ()

    Reads the entire content of the stream, and returns it as a QString. Avoid this function when working on large files, as it will consume a significant amount of memory.

    Calling readLine() is better if you do not know how much data is available.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    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: Large File Processing

    Use the QIODevice::read() and QIODevice::write() functions with a buffer of known size in a while loop.

Similar Threads

  1. Processing on the File
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2011, 19:06
  2. File Processing Application Quirk
    By sgrant327 in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2010, 18:55
  3. To large exe file
    By wydesenej in forum Installation and Deployment
    Replies: 8
    Last Post: 24th January 2009, 21:44
  4. large file management
    By sakthi in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 08:13
  5. warning while processing ui file
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2008, 19:33

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.