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

Graeme Gill graeme2 at argyllcms.com
Wed Apr 13 08:54:21 CEST 2011


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.



More information about the Qt-interest-old mailing list