summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-01-13 12:23:59 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-01-13 14:10:07 +0100
commite99435874aba270013f801316b863402ccff3fd2 (patch)
treeb77884feb633fa1a8592b767b7a7b4639a14698e
parent17b56547d6e0d9a06603231fe2384474f9144829 (diff)
Qt Service: Fix compilation with Qt 5 with define QTSERVICE_DEBUG.
Use Qt 5's new message handler within #ifdef and rewrite code use QByteArray instead of using toAscii(), which no longer exists in Qt 5. Change-Id: Iad6aa794c6578fd796e3b2bb402d3e290bdc711f Task-number: QTSOLBUG-184 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r--qtservice/src/qtservice.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/qtservice/src/qtservice.cpp b/qtservice/src/qtservice.cpp
index 5ecaa67..837254b 100644
--- a/qtservice/src/qtservice.cpp
+++ b/qtservice/src/qtservice.cpp
@@ -48,6 +48,7 @@
#if defined(QTSERVICE_DEBUG)
#include <QDebug>
+#include <QString>
#include <QFile>
#include <QTime>
#include <QMutex>
@@ -64,25 +65,31 @@ static void qtServiceCloseDebugLog()
{
if (!f)
return;
- QString ps(QTime::currentTime().toString("HH:mm:ss.zzz ") + QLatin1String("--- DEBUG LOG CLOSED ---\n\n"));
- f->write(ps.toAscii());
+ f->write(QTime::currentTime().toString("HH:mm:ss.zzz").toLatin1());
+ f->write(" --- DEBUG LOG CLOSED ---\n\n");
f->flush();
f->close();
delete f;
f = 0;
}
+#if QT_VERSION >= 0x050000
+void qtServiceLogDebug(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+#else
void qtServiceLogDebug(QtMsgType type, const char* msg)
+#endif
{
static QMutex mutex;
QMutexLocker locker(&mutex);
- QString s(QTime::currentTime().toString("HH:mm:ss.zzz "));
- s += QString("[%1] ").arg(
#if defined(Q_OS_WIN32)
- GetCurrentProcessId());
+ const qulonglong processId = GetCurrentProcessId();
#else
- getpid());
+ const qulonglong processId = getpid();
#endif
+ QByteArray s(QTime::currentTime().toString("HH:mm:ss.zzz").toLatin1());
+ s += " [";
+ s += QByteArray::number(processId);
+ s += "] ";
if (!f) {
#if defined(Q_OS_WIN32)
@@ -95,32 +102,39 @@ void qtServiceLogDebug(QtMsgType type, const char* msg)
f = 0;
return;
}
- QString ps(QLatin1String("\n") + s + QLatin1String("--- DEBUG LOG OPENED ---\n"));
- f->write(ps.toAscii());
+ QByteArray ps('\n' + s + "--- DEBUG LOG OPENED ---\n");
+ f->write(ps);
}
switch (type) {
case QtWarningMsg:
- s += QLatin1String("WARNING: ");
+ s += "WARNING: ";
break;
case QtCriticalMsg:
- s += QLatin1String("CRITICAL: ");
+ s += "CRITICAL: ";
break;
case QtFatalMsg:
- s+= QLatin1String("FATAL: ");
+ s+= "FATAL: ";
break;
case QtDebugMsg:
- s += QLatin1String("DEBUG: ");
+ s += "DEBUG: ";
break;
default:
// Nothing
break;
}
+#if QT_VERSION >= 0x050400
+ s += qFormatLogMessage(type, context, msg).toLocal8Bit();
+#elif QT_VERSION >= 0x050000
+ s += msg.toLocal8Bit();
+ Q_UNUSED(context)
+#else
s += msg;
- s += QLatin1String("\n");
+#endif
+ s += '\n';
- f->write(s.toAscii());
+ f->write(s);
f->flush();
if (type == QtFatalMsg) {
@@ -625,7 +639,11 @@ int QtServiceBasePrivate::run(bool asService, const QStringList &argList)
QtServiceBase::QtServiceBase(int argc, char **argv, const QString &name)
{
#if defined(QTSERVICE_DEBUG)
+# if QT_VERSION >= 0x050000
+ qInstallMessageHandler(qtServiceLogDebug);
+# else
qInstallMsgHandler(qtServiceLogDebug);
+# endif
qAddPostRoutine(qtServiceCloseDebugLog);
#endif