Results 1 to 13 of 13

Thread: Reading lots of Data from QProcess without freezing

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Reading lots of Data from QProcess without freezing

    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:

    Qt Code:
    1. int lines_read = 0;
    2. while (process->canReadLine() && lines_read < 10) {
    3.  
    4. QByteArray data = process->readLine();
    5.  
    6. if (!data.isEmpty()) {
    7.  
    8. Info(_log, data.constData());
    9. }
    10.  
    11. ++lines_read;
    12. }
    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)

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    The correct way is to put such task in other threads.
    The simple quick and dirty way would be to add processEvents() to your while() loop.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    The quick'n dirty way I already tried. Nothing freezes, but its far to slow (the outputrate in the QTextEdit)

    You think of observe the output of the qprocess with a thread and write the data into our internal buffer, right?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading lots of Data from QProcess without freezing

    How exactly do you input text to QTextEdit? How did you setup QTextEdit? Can't you use QPlainTextEdit instead?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    In addition to what wysota wrote, it would probably be better if you first read in to a QString or QStringList, and only after the file reading is done, to do one setText() in to the QTextEdit.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: Reading lots of Data from QProcess without freezing

    wysota: I am using append to insert line by line. Before I check every line with a QRegExp for containing links
    high_flyer: Using setText seems not to be a option, since the QTextEdit works like a console (line after line and not 500 lines once)

    Using PlainTextEdit gives a far more better performance. Thats what I need. Sadly PlainTextEdit does not support links (which I need), but maybe its better to do a tradeoff here:

    Under normal circumstances the performace of QTextEdit is ok. Only if a lot of output is produced I ran into problems. Maybe I should switch from QTextEdit to a PlainTextEdit if my internal buffer reaches a specific size (that should be an indicator, that the inserting is to slow) I should switch to a PlainTextEdit. Than I lost the links, but the program remains stable and fast.

    Nevertheless I have another idea: I already limited the maximum lines to 1000. I also observed, that sometimes my internal buffer reaches 50.000 remaining lines. In the PlainTextEdit the are inserted really fast (to fast to follow) and maybe its a good idea to skip just 49.000 lines and show only the last 1000 lines, since the other lines are useless for the user.
    Last edited by nightghost; 22nd January 2010 at 12:52.

  7. #7
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Reading lots of Data from QProcess without freezing

    Quote Originally Posted by nightghost View Post
    ... and maybe its a good idea to skip just 49.000 lines and show only the last 1000 lines, since the other lines are useless for the user.[/INDENT]
    That's just what I thought when reading this topic.
    Why would you try to show something on screen when it's already to fast to be handled in software?
    There are other ways to keep your users informed that something is happening behind the curtains...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading lots of Data from QProcess without freezing

    Quote Originally Posted by nightghost View Post
    wysota: I am using append to insert line by line.
    Bad idea, this method is terribly slow. Use QTextCursor interface instead.

    Before I check every line with a QRegExp for containing links
    Ouch, that slows it down even more. What do you need the links for?

    Using PlainTextEdit gives a far more better performance. Thats what I need. Sadly PlainTextEdit does not support links (which I need), but maybe its better to do a tradeoff here:
    It's not a big of a problem. You can visually mark the links using a syntax highlighter (which will make your QRegExp go away or at least move to a different place) and then you can handle the links by implementing mouse event handlers for your editor.

    Under normal circumstances the performace of QTextEdit is ok.
    I would certainly not agree with that statement.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    1.) A ok. I did'nt know, that this would make a difference
    2.) The output is mostly from the GCC. The QRegExp is used to detect absolute paths and make links of them to click and jump (warnings, errors messages)
    3.) Nice idea, but is this really faster? Matching the links in the SyntaxHighLighter or before adding sounds not like a big difference. But it sounds like a good idea to enable the link-feature and leave the log output untouched
    4.) Hmm, ok :-) Its fast enough to be not annoying ;-)

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading lots of Data from QProcess without freezing

    Quote Originally Posted by nightghost View Post
    3.) Nice idea, but is this really faster? Matching the links in the SyntaxHighLighter or before adding sounds not like a big difference. But it sounds like a good idea to enable the link-feature and leave the log output untouched
    In "my" version you are using plain text. In "your" version you are using rich text with injected html tags. There is a huge difference.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    nightghost (25th January 2010)

  12. #11
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    Ah ok. The SyntaxHighligher is a lot faster in formating the text then the rich-text engine. Thanks for the tip

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading lots of Data from QProcess without freezing

    The rich text engine has to parse the text each time it is being laid out (or at least each time the text changes). The syntax highlighter uses QTextDocument infrastructure.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #13
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading lots of Data from QProcess without freezing

    Thanks for the explanation. I'll have to investigate that further

Similar Threads

  1. Reading data from xls file
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2010, 09:33
  2. QProcess and reading data from xterm
    By sawerset in forum Qt Programming
    Replies: 0
    Last Post: 9th February 2009, 20:48
  3. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  4. Reading from a QProcess
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 3rd July 2008, 17:07
  5. Reading binary data
    By vermarajeev in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2007, 09:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.