Skip to content

Commit 1409c53

Browse files
committed
Merge branch 'redirect-qt-debug' into 'master'
Qt Logging Redirected to Application's Logs Closes #8852 See merge request OpenMW/openmw!5159
2 parents db7feb8 + 4b2012e commit 1409c53

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

components/platform/application.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "application.hpp"
22

3+
#include <string>
4+
35
#include <QFile>
46
#include <QOperatingSystemVersion>
57
#include <QStyle>
@@ -10,9 +12,38 @@
1012

1113
namespace Platform
1214
{
15+
static void qtMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
16+
{
17+
Debug::Level level;
18+
switch (type)
19+
{
20+
case QtDebugMsg:
21+
level = Debug::Debug;
22+
break;
23+
case QtInfoMsg:
24+
level = Debug::Info;
25+
break;
26+
case QtWarningMsg:
27+
level = Debug::Warning;
28+
break;
29+
case QtCriticalMsg:
30+
level = Debug::Error;
31+
break;
32+
case QtFatalMsg:
33+
level = Debug::Error;
34+
break;
35+
default:
36+
level = Debug::Debug;
37+
break;
38+
}
39+
40+
Log(level) << qUtf8Printable(qFormatLogMessage(type, context, msg));
41+
}
42+
1343
Application::Application(int& argc, char* argv[])
1444
: QApplication(argc, argv)
1545
{
46+
qInstallMessageHandler(qtMessageHandler);
1647
#if defined(WIN32) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
1748
init();
1849
}

0 commit comments

Comments
 (0)