aboutsummaryrefslogtreecommitdiffstats
path: root/subsurface-desktop-main.cpp
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-15 22:57:35 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-16 14:26:14 +0100
commitf2911f64ba241b3ec583cdf7da94f72b46eb8ea2 (patch)
tree264279cbe448e60307410c0e12168db43b518800 /subsurface-desktop-main.cpp
parent6161ca2083f0b4f2a7684d6d49d917df84b95b7c (diff)
downloadsubsurface-f2911f64ba241b3ec583cdf7da94f72b46eb8ea2.tar.gz
dekstop-main.cpp: install a message handler
This way the Windows binaries can properly write to log files. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'subsurface-desktop-main.cpp')
-rw-r--r--subsurface-desktop-main.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp
index 18c0f9bec..58da1fa43 100644
--- a/subsurface-desktop-main.cpp
+++ b/subsurface-desktop-main.cpp
@@ -29,12 +29,14 @@
static bool filesOnCommandLine = false;
static void validateGL();
+static void messageHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg);
int main(int argc, char **argv)
{
int i;
bool no_filenames = true;
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
+ qInstallMessageHandler(messageHandler);
QApplication *application = new QApplication(argc, argv);
(void)application;
QStringList files;
@@ -215,3 +217,27 @@ exit:
#endif
}
}
+
+// install this message handler primarily so that the Windows build can log to files
+void messageHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg)
+{
+ Q_UNUSED(ctx);
+ QByteArray localMsg = msg.toLocal8Bit();
+ switch (type) {
+ case QtDebugMsg:
+ fprintf(stdout, "%s\n", localMsg.constData());
+ break;
+ case QtInfoMsg:
+ fprintf(stdout, "%s\n", localMsg.constData());
+ break;
+ case QtWarningMsg:
+ fprintf(stderr, "%s\n", localMsg.constData());
+ break;
+ case QtCriticalMsg:
+ fprintf(stderr, "%s\n", localMsg.constData());
+ break;
+ case QtFatalMsg:
+ fprintf(stderr, "%s\n", localMsg.constData());
+ abort();
+ }
+}