[Development] Cake and eating it too for qDebug printing to system log - https://codereview.qt-project.org/89357
joerg.bornemann at digia.com
Fri Jul 11 14:14:12 CEST 2014
On 10-Jul-14 20:03, Thiago Macieira wrote:
> That means we can replace the GetConsoleWindow() call with
> AttachConsole(ATTACH_PARENT_PROCESS). If it succeeds or if it returns
> ERROR_ACCESS_DENIED, we have a console.
> For the Windows folks around: should we do this?
I've just played around with this and unfortunately channel redirection
does not work with this approach.
myapp > foo.txt
starts myapp in the background like "myapp &" on *nix would do.
The log is written to the console window and doesn't appear in the file.
cmd /c myapp > foo.txt
Blocks the shell as expected but redirection still doesn't work.
Here's the code. Maybe I missed something.
int main(int argc, char *argv)
QApplication a(argc, argv);
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
int fd = _open_osfhandle((intptr_t)h, _O_TEXT);
if (fd <= 0)
*stdout = *_fdopen(fd, "w");
setvbuf(stdout, NULL, _IONBF, 0 );
printf("Hello World from GUI app!\n");
QMetaObject::invokeMethod(&a, "quit", Qt::QueuedConnection);
More information about the Development