summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-27 12:24:55 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-27 12:24:55 +0200
commit134c1edae4c7582c1839f3c63296a4a37541ace8 (patch)
treef0524ca2c65fefa63647920b86d79f0b5d5f4331 /gui
parentf79bdb633abf5d6925b2851adab48ed24d3ab30a (diff)
main: reopen parent console
Running under CLion doesn't produce any output otherwise.
Diffstat (limited to 'gui')
-rw-r--r--gui/main.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/gui/main.cpp b/gui/main.cpp
index 16e08b6e..48fe8f74 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -1,11 +1,11 @@
#ifdef _WIN32
-# include "opentrack-library-path.h"
+# include <cstdio>
# include <stdlib.h>
# include <vector>
-# include <cstring>
# include <QCoreApplication>
# include <QFile>
# include <QString>
+# include <QtGlobal>
#else
# include <unistd.h>
#endif
@@ -46,6 +46,35 @@ void set_qt_style()
#ifdef _WIN32
+void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString &msg)
+{
+ const unsigned short* const str_ = msg.utf16();
+ auto str = reinterpret_cast<const wchar_t* const>(str_);
+ static_assert(sizeof(*str_) == sizeof(*str), "");
+
+ std::fflush(stderr);
+ if (ctx.function)
+ std::fprintf(stderr, "[%s]: %ls\n", ctx.function, str);
+ else if (ctx.file)
+ std::fprintf(stderr, "[%s:%d]: %ls\n", ctx.file, ctx.line, str);
+ else
+ std::fprintf(stderr, "%ls\n", str);
+ std::fflush(stderr);
+}
+
+void attach_parent_console()
+{
+ if (AttachConsole(ATTACH_PARENT_PROCESS))
+ {
+ // XXX c++ iostreams aren't reopened
+
+ _wfreopen(L"CON", L"w", stdout);
+ _wfreopen(L"CON", L"w", stderr);
+ _wfreopen(L"CON", L"r", stdin);
+ qInstallMessageHandler(qdebug_to_console);
+ }
+}
+
void add_win32_path()
{
// see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
@@ -105,6 +134,10 @@ WINAPI
#endif
main(int argc, char** argv)
{
+#ifdef _WIN32
+ attach_parent_console();
+#endif
+
#if QT_VERSION >= 0x050600 // flag introduced in QT 5.6. It is non-essential so might as well allow compilation on older systems.
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif