Results 1 to 9 of 9

Thread: Redirecting stdout

  1. #1
    Join Date
    Apr 2013
    Posts
    62
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Redirecting stdout

    Is there an easy way to redirect stdout to a QWidget ?

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Redirecting stdout

    Quote Originally Posted by mqt View Post
    Is there an easy way to redirect stdout to a QWidget ?
    what you mean?

  3. #3
    Join Date
    Apr 2013
    Posts
    62
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Redirecting stdout

    I have many log messages similar to cout<<"Doing something" . I want them to be shown inside a widget (like a text area) instead of stdout. Later I need to save all these contents to a log file.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,478
    Thanked 274 Times in 269 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Redirecting stdout

    Replace cout with qDebug() and read about redirecting qDebug

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Redirecting stdout

    Quote Originally Posted by mqt View Post
    I have many log messages similar to cout<<"Doing something" . I want them to be shown inside a widget (like a text area) instead of stdout. Later I need to save all these contents to a log file.
    Use the proper method of that widget in order to set text. Let's say if you have a QEditBox,
    the method doing what you want is QEditBox::setText(str* );

    For redirecting to console, use
    Qt Code:
    1. #include <qDebug>
    2. qDebug() << "text"
    To copy to clipboard, switch view to plain text mode 
    instead of cout <<;

  6. #6
    Join Date
    Apr 2013
    Posts
    62
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Redirecting stdout

    Thank you for the answer. But I am looking for someting to re-allocate the stdout with a QT, text area's (or any other text display widget's) stream. I am calling some library functions (without source code) which has stdout prints. I want all of them to be displayed in a widget. I also have a situation of calling external executable from a QPushButton SLOT. Again the output goes to stdout. I am hoping that there will be solution for atleast first scenario - library fuction.

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,478
    Thanked 274 Times in 269 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Redirecting stdout

    Read this discussion

  8. #8
    Join Date
    Apr 2019
    Location
    Sacramento, CA
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Redirecting stdout

    Hey the link is broken. I'd really appreciate any pointers in the right direction for this situation as I'm having literally the exact same problems.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Redirecting stdout

    For this:
    I also have a situation of calling external executable from a QPushButton SLOT. Again the output goes to stdout.
    QProcess is your friend.

    For output printed by DLLs loaded into your process you may have some luck intercepting your own process stdout and stderr to a file using the standard freopen() function. The use code to watch the content of the file for changes and load it into your widget.

Similar Threads

  1. Browser Redirecting
    By Ali Reza in forum General Programming
    Replies: 6
    Last Post: 15th September 2012, 07:50
  2. Redirecting stdout to a console in Qt
    By geotdw in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2012, 10:43
  3. Replies: 26
    Last Post: 23rd April 2011, 10:44
  4. redirecting ASSERTs
    By drhex in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2009, 21:59
  5. Redirecting qDebug()
    By hardgeus in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2006, 01:39

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.