From 944318b63ee898ebc2f052734865ac5679e58623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 12 Nov 2013 08:07:27 +0100 Subject: [PATCH] fixed some Qt4/Qt5 compilation issues added first version of messageHandler --- .../comic_vine/comic_vine_dialog.cpp | 6 +- YACReaderLibrary/main.cpp | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 65b1bd00..0d4ab235 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -7,7 +7,11 @@ #include #include #include -#include +#if QT_VERSION >= 0x050000 + #include +#else + #include +#endif #include #include #include "data_base_management.h" diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index c3135756..3216e7db 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -4,6 +4,14 @@ #include #include #include +#include +#include +#include +#include + +#if QT_VERSION >= 0x050000 +#include +#endif #include "yacreader_global.h" #include "startup.h" @@ -12,6 +20,43 @@ #define PICTUREFLOW_QT4 1 +#if QT_VERSION >= 0x050000 +void yacreaderMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &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(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); + + QFile outFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/yacreaderlibrary.log"); + + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream ts(&outFile); + ts << QDateTime::currentDateTime().toString() << " - " << txt << endl; +} +#else +void yacreaderMessageHandler(QtMsgType type, const char *) +{ + +} +#endif + + //interfaz al servidor Startup * s; @@ -19,6 +64,14 @@ int main( int argc, char ** argv ) { QApplication app( argc, argv ); +#if QT_VERSION >= 0x050000 + qInstallMessageHandler(yacreaderMessageHandler); +#else + qInstallMsgHandler(yacreaderMessageHandler); +#endif + + qDebug() << "YACReaderLibrary started" << endl; + QTranslator translator; QString sufix = QLocale::system().name(); translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix); @@ -65,5 +118,7 @@ int main( int argc, char ** argv ) s->stop(); delete s; + qDebug() << "YACReaderLibrary closed" << endl; + return ret; }