Is there an easy way to redirect stdout to a QWidget ?
Is there an easy way to redirect stdout to a QWidget ?
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.
Replace cout with qDebug() and read about redirecting qDebug
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
instead of cout <<;Qt Code:
#include <qDebug> qDebug() << "text"To copy to clipboard, switch view to plain text mode
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.
Read this discussion
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.
For this:QProcess is your friend.I also have a situation of calling external executable from a QPushButton SLOT. Again the output goes to stdout.
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.
Bookmarks