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:
12
third_party/QsLog/QsLogDestConsole.cpp
vendored
12
third_party/QsLog/QsLogDestConsole.cpp
vendored
@ -39,11 +39,17 @@ void QsDebugOutput::output( const QString& message )
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
void QsDebugOutput::output( const QString& message )
|
void QsDebugOutput::output( const QString& message )
|
||||||
{
|
{
|
||||||
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), message.utf16(), message.size(), NULL, NULL);
|
HANDLE stdErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), L"\n", 1, NULL, NULL);
|
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));
|
fprintf(stdout, "%s\n", qPrintable(message));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user