Results 1 to 7 of 7

Thread: Reading standard error from a process

  1. #1
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Reading standard error from a process

    Hello Qt developers! I have the following problem, hope you'll be able to help me.

    From my Qt app I run a QProcess - an application, which normally prints some messages to a console screen. I want to capture these messages in my app using readAllStandardError(), but it gives no result. It eventually appears, but only after i call terminate() on a QProcess, when cumulated messages appear at once.

    What should I do to see the messages just as they are printed?

  2. #2
    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: Reading standard error from a process

    an application, which normally prints some messages to a console screen.
    Probably messages are buffered, try to flush the std error output in this application ( fflush(stderr), this was posted few times on the forum ).

  3. #3
    Join Date
    Feb 2011
    Location
    Romania
    Posts
    53
    Thanks
    1
    Thanked 11 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading standard error from a process

    And if you want to capture real-time messages, connect your slot to QProcess::readyReadStandardError.

  4. #4
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading standard error from a process

    The problem is that I can't change anything in the message sender application (It's not my application), I can only manipulate the Qt application (my aplication, receiver of messages).
    So I need something like QProcess::flush()...

  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: Reading standard error from a process

    You may try to pass QIODevice::Unbuffered flag when starting the process. I don't know if it works, never tried that.

  6. #6
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading standard error from a process

    instead of showing the messages in the console screen pass them to a file or data array and print them to the console afterwards, u can access the file or data array anytime.

    on the other hand , if your data is stored but not shown try to insert:
    QApplication:rocessEvents() ;
    based on how often errors are shown

  7. #7
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading standard error from a process

    Quote Originally Posted by stampede View Post
    You may try to pass QIODevice::Unbuffered flag when starting the process. I don't know if it works, never tried that.
    Doesn't work in this case.

    Anyway, thanks for all the replies!

Similar Threads

  1. Error in Qlistmodel standard item
    By maarvi in forum Newbie
    Replies: 3
    Last Post: 28th June 2011, 11:17
  2. unknown error reading svg file
    By RickF in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2010, 02:12
  3. The process could not be started! Error
    By jujose in forum Installation and Deployment
    Replies: 3
    Last Post: 27th February 2010, 17:25
  4. Replies: 2
    Last Post: 2nd June 2008, 08:45
  5. QProcess +standard error + windows
    By antonio.r.tome in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2006, 14:58

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.