Results 1 to 2 of 2

Thread: Processing Large Text File in Qt

  1. #1
    Join Date
    Jan 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Processing Large Text File in Qt

    Hi,

    I am reading a Large txt file and processing some value. The program suddenly exits at about 4000000 record approximately. The file size is 7228916 lines or records. Here is my code snippet:

    Qt Code:
    1. QTextStream in(&fEngg);
    2. slEnggFileRecs.clear();
    3.  
    4. etmrOldPlot.start();
    5. iFileIndx = 0;
    6. slXVals1.clear();
    7. while(!in.atEnd()) {
    8. slEnggFileRecs.append(in.readLine());
    9. if(iFileIndx > 0) {
    10. slXVals1.append(slEnggFileRecs.at(iFileIndx).split(',').at(1));
    11. }
    12. ++iFileIndx;
    13. qInfo() << "iFileIndx:" << iFileIndx;
    14. }
    15. qInfo() << "RunTab: Read Engg file:" << etmrOldPlot.elapsed();
    16. qInfo() << "Total Recs in Engg File:" << slEnggFileRecs.length() - 1 << " slXVals1.len:" << slXVals1.length();
    To copy to clipboard, switch view to plain text mode 

    Is there any solution for this? Thanks in adv.

    Dan

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Processing Large Text File in Qt

    I don't see any obvious bug in this, except for possibly one:

    Qt Code:
    1. slXVals1.append(slEnggFileRecs.at(iFileIndx).split(',').at(1));
    To copy to clipboard, switch view to plain text mode 
    If the line is blank or has only one field in it, "at(1)" will likely crash.

    But some questions (which you might have good reasons for doing):

    1 - Why do you store the entire contents of the file in "slEnggFileRecs"? Do you need to go back and process the strings after reading them in? If not, then you're just creating excess overhead.

    Qt Code:
    1. qInfo() << "RunTab: Read Engg file:" << etmrOldPlot.elapsed();
    To copy to clipboard, switch view to plain text mode 
    2 - Storing the line in "slEnggFileRecs" and then retrieving it to split it is inefficient. Read it into a QString and if you have to, save the QString in "slEnggFileRecs" but also pass it to the split() method. Using a temporary QString would also allow you to easily check to see if it is empty. Storing the result of the split in a temporary QStringList would allow you to determine that it had enough pieces. Try it both ways and see if your elapsed time improves.

    3 - "slXVals1" looks like it could be an X coordinate or at least a numerical value. Why store it as a string? Why not convert it immediately to a number and store that?

    Qt Code:
    1. qInfo() << "Total Recs in Engg File:" << slEnggFileRecs.length() - 1 << " slXVals1.len:" << slXVals1.length();
    To copy to clipboard, switch view to plain text mode 

    4 - You have already counted the number of lines and x values in "iFileIndx". If you are storing the records only so you can get the count, then there is no need to do that since you have this variable.
    Last edited by d_stranz; 3rd February 2026 at 19:49.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Pre-processing entered text in QTextDocument
    By srazi in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2017, 00:19
  2. Large File Processing
    By sankar in forum Newbie
    Replies: 2
    Last Post: 31st August 2012, 00:17
  3. Thread Search in text file large
    By marcos.miranda in forum Newbie
    Replies: 11
    Last Post: 12th June 2012, 21:54
  4. Advice: Reading large text file.
    By enricong in forum Qt Programming
    Replies: 7
    Last Post: 16th July 2011, 13:11
  5. Sending large datagrams(very large)
    By marcel in forum General Programming
    Replies: 1
    Last Post: 16th February 2008, 22:55

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