Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

[Solved] Update QTextEdit content with changes of a big trace file.

$
0
0
Hi there! I’m trying to present the contents of a trace file into a QTextEdit, since this file is changing constantly I need to implement a mechanism to regularly update the QTextEdit with the changes. The trace file is a text file that has a pretty big size, it may grow up to 110MB when it is rolled and size comes back to 0. So far what I’m doing is calling a function (using a QTimer) that checks the trace file size: void MainWindow::checkTraceFileSize() {     qint64 Size = QFile("trace.dat").size();     if(Size!=TraceFileSize) traceFileChanged();     TraceFileSize=Size;     } If the trace file has changed it’s size traceFileChanged is called: void MainWindow::traceFileChanged() {     long nLine=0;     QFile TraceFile("trace.dat");     if (TraceFile.open(QIODevice::ReadOnly)) {         QTextStream in(&TraceFile);         while(!in.atEnd()) {             if(nLine>=TraceFileLine) {  //New Lines since last check...                 processLine(in.readLine());   //Add the line to the QTextEdit                 TraceFileLine++;                 }             else in.readLine();             nLine++;             }         }     TraceFile.close();     } Basically if the size has changed I read the big file line after line discarding the ones that had already been written to the QTextEdit and adding the new ones to it. BUT since the trace file is so big the app freezes for one or two seconds each time new lines are added to the file. To put it simply I need to implement some kind of “tail -f” to a QTextEdit of a big file. Is there a better way to achieve this? Thanks in advance!

Viewing all articles
Browse latest Browse all 18427

Trending Articles