diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 1e350fd88..7308b8d9a 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,7 @@ static constexpr u32 GDB_SERVER_POLLING_INTERVAL = 1; namespace QtHost { static bool PerformEarlyHardwareChecks(); static bool EarlyProcessStartup(); +static void MessageOutputHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg); static void RegisterTypes(); static bool InitializeConfig(); static void SetAppRoot(); @@ -201,6 +203,9 @@ bool QtHost::EarlyProcessStartup() } #endif + // redirect qt errors + qInstallMessageHandler(MessageOutputHandler); + Error error; if (System::ProcessStartup(&error)) [[likely]] return true; @@ -210,6 +215,33 @@ bool QtHost::EarlyProcessStartup() return false; } +void QtHost::MessageOutputHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) +{ + const char* function = context.function ? context.function : ""; + const std::string smsg = msg.toStdString(); + switch (type) + { + case QtDebugMsg: + DEBUG_LOG("qDebug({}): {}", function, smsg); + break; + case QtInfoMsg: + INFO_LOG("qInfo({}): {}", function, smsg); + break; + case QtWarningMsg: + WARNING_LOG("qWarning({}): {}", function, smsg); + break; + case QtCriticalMsg: + ERROR_LOG("qCritical({}): {}", function, smsg); + break; + case QtFatalMsg: + ERROR_LOG("qFatal({}): {}", function, smsg); + Y_OnPanicReached(smsg.c_str(), function, context.file ? context.file : "", context.line); + default: + ERROR_LOG("({}): {}", function, smsg); + break; + } +} + bool QtHost::InBatchMode() { return s_batch_mode;