Skip to content

Commit 6521cb8

Browse files
committed
qml: Add qInstallMessageHandler
1 parent 2181a66 commit 6521cb8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/qml/bitcoin.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <init.h>
88
#include <interfaces/node.h>
9+
#include <logging.h>
910
#include <node/context.h>
1011
#include <node/ui_interface.h>
1112
#include <noui.h>
@@ -25,9 +26,14 @@
2526
#include <QQmlApplicationEngine>
2627
#include <QQmlContext>
2728
#include <QQuickWindow>
29+
#include <QString>
2830
#include <QStringLiteral>
2931
#include <QUrl>
3032

33+
QT_BEGIN_NAMESPACE
34+
class QMessageLogContext;
35+
QT_END_NAMESPACE
36+
3137
#if defined(QT_STATICPLUGIN)
3238
#include <QtPlugin>
3339
Q_IMPORT_PLUGIN(QtQuick2DialogsPlugin);
@@ -61,6 +67,17 @@ bool InitErrorMessageBox(
6167
qGuiApp->exec();
6268
return false;
6369
}
70+
71+
/* qDebug() message handler --> debug.log */
72+
void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
73+
{
74+
Q_UNUSED(context);
75+
if (type == QtDebugMsg) {
76+
LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
77+
} else {
78+
LogPrintf("GUI: %s\n", msg.toStdString());
79+
}
80+
}
6481
} // namespace
6582

6683

@@ -154,6 +171,9 @@ int QmlGuiMain(int argc, char* argv[])
154171
return EXIT_FAILURE;
155172
}
156173

174+
// Install qDebug() message handler to route to debug.log
175+
qInstallMessageHandler(DebugMessageHandler);
176+
157177
qInfo() << "Graphics API in use:" << QmlUtil::GraphicsApi(window);
158178

159179
return qGuiApp->exec();

0 commit comments

Comments
 (0)