Skip to content

Commit

Permalink
Share qInstallMessageHandler between QWidget and QML code
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 27, 2021
1 parent 2aa44e6 commit 9208b5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
14 changes: 1 addition & 13 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ static bool InitSettings()
return true;
}

/* qDebug() message handler --> debug.log */
void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
{
Q_UNUSED(context);
if (type == QtDebugMsg) {
LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
} else {
LogPrintf("GUI: %s\n", msg.toStdString());
}
}

static int qt_argc = 1;
static const char* qt_argv = "bitcoin-qt";

Expand Down Expand Up @@ -591,8 +580,7 @@ int GuiMain(int argc, char* argv[])
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
qApp->installNativeEventFilter(new WinShutdownMonitor());
#endif
// Install qDebug() message handler to route to debug.log
qInstallMessageHandler(DebugMessageHandler);

// Allow parameter interaction before we create the options model
app.parameterSetup();
GUIUtil::LogQtInfo();
Expand Down
26 changes: 24 additions & 2 deletions src/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@
#include <qt/bitcoin.h>
#endif // USE_QML

#include <logging.h>
#include <noui.h>
#include <util/system.h>
#include <util/threadnames.h>
#include <util/translation.h>
#include <util/url.h>

#include <QCoreApplication>

#include <functional>
#include <string>
#include <tuple>

#include <QCoreApplication>
#include <QString>

QT_BEGIN_NAMESPACE
class QMessageLogContext;
QT_END_NAMESPACE

#if defined(QT_STATICPLUGIN)
#include <QtPlugin>
#if defined(QT_QPA_PLATFORM_XCB)
Expand All @@ -41,6 +47,19 @@ extern const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](cons
};
UrlDecodeFn* const URL_DECODE = urlDecode;

namespace {
/* qDebug() message handler --> debug.log */
void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
Q_UNUSED(context);
if (type == QtDebugMsg) {
LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
} else {
LogPrintf("GUI: %s\n", msg.toStdString());
}
}
} // namespace

int main(int argc, char* argv[])
{
#ifdef WIN32
Expand All @@ -54,6 +73,9 @@ int main(int argc, char* argv[])
// Subscribe to global signals from core.
noui_connect();

// Install qDebug() message handler to route to debug.log
qInstallMessageHandler(DebugMessageHandler);

#if USE_QML
return QmlGuiMain(argc, argv);
#else
Expand Down

0 comments on commit 9208b5b

Please sign in to comment.