Hello,
I want to read a lot of data from a program started with QProcess and show the output in at QTextEdit. The problem is to get a good tradeoff between speed and response time (The programs are producing really a lot of output):
In our first implementation wie used QProcess::readAllStandardOutput(), but then the GUI freezed and it was nearly impossible to do something.
then we used in our SLOT:
int lines_read = 0;
while (process->canReadLine() && lines_read < 10) {
if (!data.isEmpty()) {
Info(_log, data.constData());
}
++lines_read;
}
int lines_read = 0;
while (process->canReadLine() && lines_read < 10) {
QByteArray data = process->readLine();
if (!data.isEmpty()) {
Info(_log, data.constData());
}
++lines_read;
}
To copy to clipboard, switch view to plain text mode
After the program is finsihed in the finished handler all remaining output is written once into the log, then the GUI only freezes shortly (1-2 sec), but that is ok. the "Info()" macro inserts the data into a buffer and is then written to the QTextEdit.
The GUI is not freezing anymore while writing the output, but the output is written far to slow (3 min program and 17 min output (after the program has finished) If I increase the lines read once from 10 to lets say 100 is faster (but not fast enough), but the GUI is freezing again. I also played around with QApplication::processEvents(), but that did not solve the problem. (No freezing, but not fast enough either)
I assume, that the (one of the problems) problem is in reading the output from the QProcess, because after the QProcess is finsihed all data is written once to the buffer, and the data is only inserted into the QTextEdit.
Does anyone has a good guess what to do? Maybe use a separate Thread to read the output and/or write the data to the QTextEdit (if this is possible at all)
Bookmarks