Results 1 to 5 of 5

Thread: QProcess, readyRead, QTextEdit

  1. #1
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb QProcess, readyRead, QTextEdit

    I want to be able to 'continuously' append the output of a command-line into a QTextEdit.

    I have a GUI app that uses QProcess to start a command-line app. The CL app has tons of output via printf's.

    I am current connecting to the readyRead() signal of the QProcess and using readAllStandardOutput() to post the info into the QTextEdit. The problem with this is that I only get the output once the CL app is finished.

    What do I need to do to get the output as it happens?

    TIA, Sam.

  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: QProcess, readyRead, QTextEdit

    what happens if you use the readyReadStandardOutput () signal instead?
    ==========================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
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess, readyRead, QTextEdit

    The CL app has tons of output via printf's
    Is it your command line application ? If yes, you may consider flushing the stdout after printf:

    Qt Code:
    1. printf("A text");
    2. fflush(stdout);
    To copy to clipboard, switch view to plain text mode 

    stdout is buffered, but it should flush automatically after reaching new line character.

    Also try to set read channel for QProcess:
    Qt Code:
    1. proc->setReadChannel(QProcess::StandardOutput);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess, readyRead, QTextEdit

    Got it working better...

    printf and fflush and QProcess::StandardOutput and readyReadStandardOutput () did the trick.

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProcess, readyRead, QTextEdit

    printf and fflush (...)
    I think you can even disable buffering of the stdout in your app:
    Qt Code:
    1. setbuf(stdout,NULL);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 28th October 2010, 12:33
  2. Not getting readyRead from a QUdpSocket
    By evelBist in forum Newbie
    Replies: 3
    Last Post: 20th July 2010, 19:43
  3. readyRead problem
    By fruzzo in forum Qt Programming
    Replies: 11
    Last Post: 2nd September 2009, 19:50
  4. QProcess and Qtextedit problem
    By skumar434 in forum Qt Programming
    Replies: 1
    Last Post: 17th March 2009, 18:24
  5. QExtSerialPort with readyRead()
    By tho97 in forum Qt Programming
    Replies: 4
    Last Post: 27th August 2008, 20:18

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.