PDA

View Full Version : Redirecting stdout



mqt
1st July 2013, 17:57
Is there an easy way to redirect stdout to a QWidget ?

saman_artorious
2nd July 2013, 06:02
Is there an easy way to redirect stdout to a QWidget ?

what you mean?

mqt
2nd July 2013, 06:12
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.

Lesiok
2nd July 2013, 06:50
Replace cout with qDebug() and read about redirecting qDebug (http://qt-project.org/doc/qt-4.8/qtglobal.html#qInstallMsgHandler)

saman_artorious
2nd July 2013, 07:14
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


#include <qDebug>
qDebug() << "text"

instead of cout <<;

mqt
2nd July 2013, 08:58
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.

Lesiok
2nd July 2013, 09:46
Read this discussion (http://www.qtforum.org/article/24554/displaying-std-cout-in-a-text-box.html?d56d6d32#post86997)

earlyriser01
18th April 2019, 18:25
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.

ChrisW67
19th April 2019, 05:20
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.