Merge pull request #1464 from Ryex/fix/windows-console-attach
[Windows] Fix attaching logs to console
This commit is contained in:
@ -135,13 +135,8 @@
|
||||
#include "updater/MacSparkleUpdater.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "WindowsConsole.h"
|
||||
#endif
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
@ -168,31 +163,15 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
|
||||
|
||||
Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
||||
{
|
||||
#if defined Q_OS_WIN32
|
||||
// attach the parent console
|
||||
if(AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
{
|
||||
// if attach succeeds, reopen and sync all the i/o
|
||||
if(freopen("CON", "w", stdout))
|
||||
{
|
||||
std::cout.sync_with_stdio();
|
||||
}
|
||||
if(freopen("CON", "w", stderr))
|
||||
{
|
||||
std::cerr.sync_with_stdio();
|
||||
}
|
||||
if(freopen("CON", "r", stdin))
|
||||
{
|
||||
std::cin.sync_with_stdio();
|
||||
}
|
||||
auto out = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
DWORD written;
|
||||
const char * endline = "\n";
|
||||
WriteConsole(out, endline, strlen(endline), &written, NULL);
|
||||
// attach the parent console if stdout not already captured
|
||||
if (AttachWindowsConsole()) {
|
||||
consoleAttached = true;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user