mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Better console output in Windows
This way QtCreator can actually get the output from the app.
This commit is contained in:
16
third_party/QsLog/QsLogDestConsole.cpp
vendored
16
third_party/QsLog/QsLogDestConsole.cpp
vendored
@ -39,11 +39,17 @@ void QsDebugOutput::output( const QString& message )
|
||||
#include <Windows.h>
|
||||
void QsDebugOutput::output( const QString& message )
|
||||
{
|
||||
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), message.utf16(), message.size(), NULL, NULL);
|
||||
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), L"\n", 1, NULL, NULL);
|
||||
|
||||
fprintf(stdout, "%s\n", qPrintable(message));
|
||||
fflush(stdout);
|
||||
HANDLE stdErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
DWORD mode;
|
||||
if (GetConsoleMode(stdErr, &mode)) {
|
||||
// Real console attached — use Unicode-aware WriteConsoleW
|
||||
WriteConsoleW(stdErr, message.utf16(), message.size(), NULL, NULL);
|
||||
WriteConsoleW(stdErr, L"\n", 1, NULL, NULL);
|
||||
} else {
|
||||
// Pipe (Qt Creator, redirect, etc.) — use stdio
|
||||
fprintf(stdout, "%s\n", qPrintable(message));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user