Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share qInstallMessageHandler between QWidget and QML code #25

Merged
merged 1 commit into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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