tags:

views:

2402

answers:

3

I've been learning qt on windows for a little while (background in unix/embedded) and would like to have stderr/stdout dumped out somewhere (unit test/event logging/debug) from my win32 qt GUI app. That seems to be a tall order in windows and I found this post on stackoverflow which explains why.

I find myself wondering why qt doesn't have a simple mechanism for performing some of the suggestions in the post for debug builds.

Does such a facility already exist in qt or am I left to roll my own (or find a syslog lib)?

+7  A: 

qDebug() and related functions are handy for that sort of thing - will get sent to the debugger (if you're using Qt Creator, that will pick those up easily!)

#include <QDebug>

qDebug() << "x is: " << x;
Paul Dixon
That is exactly what I was looking for, thanks!
tim
+1  A: 

You can always start your programs from the command line to see stdout output (cmd.exe). Also, like Paul Dixon said, by using qDebug() you should be able to see the output in the debugger.

#include <QDebug>
...
{
   ...
   int x = 5;
   qDebug() << "x is: " << x;
}
nmuntz
Thanks for the code snippet, that was helpful.
tim
+2  A: 

One cheap way is to simply reopen stdout/err (well atleast in win32, I'm assuming it'll work with Qt as well)

#include <stdio>

//add this at the beginning of your main
freopen("c:\\temp\\stdout.txt","w",stdout);
freopen("c:\\temp\\stderr.txt","w",stderr);

If you need some more serious tracing/logging consider e.g. log4cxx

nos
Thanks for the pointer, I have my own logging infrastructure I invented that looks a whole lot like log4cxx. I will have to have a closer look at that one to see if I should use that instead.
tim