diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 9ccb519b6..4f9ae7d45 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -58,6 +58,7 @@ #include #include #include +#include #include "ui_Launcher.h" #include "ui_NoOfficialHangar.h" @@ -573,6 +574,25 @@ private: SGPath _foundPath; }; +static void simgearMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + sgDebugPriority mappedPriority = SG_WARN; + switch (type) { + case QtDebugMsg: mappedPriority = SG_DEBUG; break; + case QtInfoMsg: mappedPriority = SG_INFO; break; + case QtWarningMsg: mappedPriority = SG_WARN; break; + case QtCriticalMsg: mappedPriority = SG_ALERT; break; + case QtFatalMsg: mappedPriority = SG_POPUP; break; + } + + static const char* nullFile = ""; + const char* file = context.file ? context.file : nullFile; + sglog().log(SG_GUI, mappedPriority, file, context.line, msg.toStdString()); + if (type == QtFatalMsg) { + abort(); + } +} + namespace flightgear { @@ -593,6 +613,10 @@ void initApp(int& argc, char** argv, bool doInitQSettings) // and may crash if it is freed // http://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication + // log to simgear instead of the console from Qt, so we go to + // whichever log locations SimGear has configured + qInstallMessageHandler(simgearMessageOutput); + QApplication* app = new QApplication(s_argc, argv); app->setOrganizationName("FlightGear"); app->setApplicationName("FlightGear");