[Qt-interest] How to capture stdout and redirect it to the gui?

Frank Hemer frank at hemer.org
Thu Jan 27 15:45:34 CET 2011


On Wednesday 26 January 2011 23:42:53 K. Frank wrote:
> Hello Qt!
>
> I would like to "capture" stdout and redirect it to a logging
> window, for example, a QTextEdit.
>
> Jochen Ulrich gave a good solution for doing this with std::cout
> a few years back, see:
>
>    http://lists.trolltech.com/qt-interest/2005-06/thread00166-0.html
>
> I am using this, and it works well for std::cout, but now I
> am using a C library that writes stuff to stdout (not C++'s
> std::cout), and I would like to capture this output as well.
>
> I am using Qt 4.6.1 on windows 7 with mingw.
>
> This is not overly urgent.  I found a posting that shows how
> to set "config += console" in the .pro file so that stdout output
> will appear in the console window from which I launch my Qt
> application.  So I can get the data this way, and make do.
>
> But I would prefer, if possible, to display the output in the
> gui, rather than a separate console window.
>
> Would someone know of a solution or have suggestions about
> things to try?

Take a look at QtGlobal::QtMsgHandler and QtGlobal::qInstallMsgHandler
 - I think this is what you are looking for.

Frank



More information about the Qt-interest-old mailing list