From 94eb1df58b4ad4e25941782832d20e1c8d57f0c5 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 16 Aug 2020 12:04:15 +0200 Subject: [PATCH] rbutil: Logger Qt6 fixes. Fix various issues with building CuteLogger with Qt6. Change-Id: Iceac8f8a19f6703868c5a41b725d3cd69c724239 --- rbutil/rbutilqt/logger/include/Logger.h | 3 ++- rbutil/rbutilqt/logger/src/AbstractStringAppender.cpp | 11 ++++++----- rbutil/rbutilqt/logger/src/Logger.cpp | 11 ++++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/rbutil/rbutilqt/logger/include/Logger.h b/rbutil/rbutilqt/logger/include/Logger.h index 509bc5f435..941e556eb9 100644 --- a/rbutil/rbutilqt/logger/include/Logger.h +++ b/rbutil/rbutilqt/logger/include/Logger.h @@ -18,6 +18,7 @@ #include #include #include +#include // Local #include "CuteLogger_global.h" @@ -224,7 +225,7 @@ class CUTELOGGERSHARED_EXPORT LoggerTimingHelper private: Logger* m_logger; - QTime m_time; + QElapsedTimer m_time; Logger::LogLevel m_logLevel; Logger::TimingMode m_timingMode; const char* m_file; diff --git a/rbutil/rbutilqt/logger/src/AbstractStringAppender.cpp b/rbutil/rbutilqt/logger/src/AbstractStringAppender.cpp index ce64aaeb43..ea5883f744 100644 --- a/rbutil/rbutilqt/logger/src/AbstractStringAppender.cpp +++ b/rbutil/rbutilqt/logger/src/AbstractStringAppender.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -155,12 +155,13 @@ QByteArray AbstractStringAppender::qCleanupFuncinfo(const char* name) } bool hasLambda = false; - QRegExp lambdaRegex("::"); - int lambdaIndex = lambdaRegex.indexIn(QString::fromLatin1(info)); + QRegularExpression lambdaRegex("::"); + QRegularExpressionMatch match = lambdaRegex.match(QString::fromLatin1(info)); + int lambdaIndex = match.capturedStart(); if (lambdaIndex != -1) { hasLambda = true; - info.remove(lambdaIndex, lambdaRegex.matchedLength()); + info.remove(lambdaIndex, match.capturedLength()); } // operator names with '(', ')', '<', '>' in it @@ -405,7 +406,7 @@ QString AbstractStringAppender::formattedString(const QDateTime& timeStamp, Logg // Filename without a path else if (command == QLatin1String("file")) - chunk = QString(QLatin1String(file)).section(QRegExp("[/\\\\]"), -1); + chunk = QString(QLatin1String(file)).section(QRegularExpression("[/\\\\]"), -1); // Source line number else if (command == QLatin1String("line")) diff --git a/rbutil/rbutilqt/logger/src/Logger.cpp b/rbutil/rbutilqt/logger/src/Logger.cpp index 16a18db728..689bc42e80 100644 --- a/rbutil/rbutilqt/logger/src/Logger.cpp +++ b/rbutil/rbutilqt/logger/src/Logger.cpp @@ -600,8 +600,13 @@ Logger::~Logger() // Cleanup appenders QMutexLocker appendersLocker(&d->loggerMutex); +#if QT_VERSION >= 0x050e00 + QSet deleteList(QSet(d->appenders.begin(), d->appenders.end())); + deleteList.unite(QSet(d->categoryAppenders.values().begin(), d->categoryAppenders.values().end())); +#else QSet deleteList(QSet::fromList(d->appenders)); deleteList.unite(QSet::fromList(d->categoryAppenders.values())); +#endif qDeleteAll(deleteList); appendersLocker.unlock(); @@ -1032,7 +1037,11 @@ void LoggerTimingHelper::start(const char* msg, ...) { va_list va; va_start(va, msg); +#if QT_VERSION >= 0x050500 + m_block = QString().vasprintf(msg, va); +#else m_block = QString().vsprintf(msg, va); +#endif va_end(va); m_time.start(); @@ -1062,7 +1071,7 @@ LoggerTimingHelper::~LoggerTimingHelper() else message = QString(QLatin1String("\"%1\" finished in ")).arg(m_block); - int elapsed = m_time.elapsed(); + qint64 elapsed = m_time.elapsed(); if (elapsed >= 10000 && m_timingMode == Logger::TimingAuto) message += QString(QLatin1String("%1 s.")).arg(elapsed / 1000); else