From 9db62a6475378ddc2f7076132c2eb8e3d48007b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 12 Nov 2013 19:35:41 +0100 Subject: [PATCH] added message handler for Qt4 --- YACReaderLibrary/main.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index 3216e7db..33b1a97b 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -11,8 +11,11 @@ #if QT_VERSION >= 0x050000 #include +#else +#include #endif + #include "yacreader_global.h" #include "startup.h" #include "yacreader_local_server.h" @@ -50,9 +53,32 @@ void yacreaderMessageHandler(QtMsgType type, const QMessageLogContext &context, ts << QDateTime::currentDateTime().toString() << " - " << txt << endl; } #else -void yacreaderMessageHandler(QtMsgType type, const char *) +void yacreaderMessageHandler(QtMsgType type, const char * msg) { + QString txt; + switch (type) { + case QtDebugMsg: + txt = QString("Debug: %1").arg(msg); + break; + case QtWarningMsg: + txt = QString("Warning: %1").arg(msg); + break; + case QtCriticalMsg: + txt = QString("Critical: %1").arg(msg); + break; + case QtFatalMsg: + txt = QString("Fatal: %1").arg(msg); + break; + } + + QDir().mkpath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); + + QFile outFile(QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/yacreaderlibrary.log"); + + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << QDateTime::currentDateTime().toString() << " - " << txt << endl; } #endif