rbutil: Logger Qt6 fixes.

Fix various issues with building CuteLogger with Qt6.

Change-Id: Iceac8f8a19f6703868c5a41b725d3cd69c724239
This commit is contained in:
Dominik Riebeling 2020-08-16 12:04:15 +02:00
parent cd352d9052
commit 94eb1df58b
3 changed files with 18 additions and 7 deletions

View file

@ -18,6 +18,7 @@
#include <QString>
#include <QDebug>
#include <QDateTime>
#include <QElapsedTimer>
// 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;

View file

@ -20,7 +20,7 @@
#include <QReadLocker>
#include <QWriteLocker>
#include <QDateTime>
#include <QRegExp>
#include <QRegularExpression>
#include <QCoreApplication>
#include <QThread>
@ -155,12 +155,13 @@ QByteArray AbstractStringAppender::qCleanupFuncinfo(const char* name)
}
bool hasLambda = false;
QRegExp lambdaRegex("::<lambda\\(.*\\)>");
int lambdaIndex = lambdaRegex.indexIn(QString::fromLatin1(info));
QRegularExpression lambdaRegex("::<lambda\\(.*?\\)>");
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"))

View file

@ -600,8 +600,13 @@ Logger::~Logger()
// Cleanup appenders
QMutexLocker appendersLocker(&d->loggerMutex);
#if QT_VERSION >= 0x050e00
QSet<AbstractAppender*> deleteList(QSet<AbstractAppender*>(d->appenders.begin(), d->appenders.end()));
deleteList.unite(QSet<AbstractAppender*>(d->categoryAppenders.values().begin(), d->categoryAppenders.values().end()));
#else
QSet<AbstractAppender*> deleteList(QSet<AbstractAppender*>::fromList(d->appenders));
deleteList.unite(QSet<AbstractAppender*>::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