[Qt-interest] stdout of MSWin GUI application run from console

Scott Aron Bloom Scott.Bloom at onshorecs.com
Wed Apr 13 17:37:38 CEST 2011


I was hoping this would work...
And with some minor tweaking it worked like a charm.. just as
advertised...

I haven't tested stdin but frankly, I have very little use for that...

Couple of issues I found...

The fileno(stdout) (and the others) is already set by the time main is
called...  I created a TRIVIAL Qt GUI based app..  

If I call the app > foo, to redirect the stdout to the foo.  It works
like a charm, WITHOUT your code...

If I use your code and force a reopen, the > breaks and the output only
goes to the console

Scott

-----Original Message-----
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of Graeme Gill
Sent: Tuesday, April 12, 2011 11:54 PM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] stdout of MSWin GUI application run from console

Hi,
	I'm sure that this has been raised before, but why doesn't a QT
MSWin GUI application fix the stdin, stdout & stderr to go to the
console it's started from (when it's started from a console), so that it
behaves the same as QT on other platforms (ie. Linux & OS X) ?

Sure, I can fix it myself using something like:

#ifdef Q_WS_WIN
     {
         BOOL (WINAPI *AttachConsole)(DWORD dwProcessId)

	// AttachConsole is available in WinXP and above
         *(FARPROC *)&AttachConsole =
           GetProcAddress(LoadLibraryA("kernel32.dll"),
"AttachConsole");

             if (AttachConsole != NULL && AttachConsole(((DWORD)-1))) {
                 if (_fileno(stderr) == -1)
                     freopen("CONOUT$","wb",stdout);
                 if (_fileno(stderr) == -1)
                     freopen("CONOUT$","wb",stderr);
                 if (_fileno(stdin) == -1)
                     freopen("CONIN$","wb",stdin);
             }
     }
#endif // Q_WS_WIN

but wouldn't it be better if QApplication did this ?

Thanks,
	Graeme Gill.
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list