From c9cdbcb12f80cd72905e49ce1a673eae9f559ca3 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 14 Feb 2014 13:36:38 +0100 Subject: Add const overload for QLoggingCategory::operator()() Change 85e57653 caused a compile error for code that does Q_DECLARE_LOGGING_CATEGORY(cat); //.. qCDebug(cat()) << // ... error: C3848: expression having type 'const QLoggingCategory' would lose some const-volatile qualifiers in order to call 'QLoggingCategory &QLoggingCategory::operator ()(void)' This is a regression from Qt 5.2. Fix the error by adding a const version of operator()(). Change-Id: I2fb04f2e155962adee0f98089fc5a159000bef56 Reviewed-by: Alex Blasche Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/io/qloggingcategory.cpp | 8 ++++++++ src/corelib/io/qloggingcategory.h | 1 + tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 168087659f..f37b9575aa 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -273,6 +273,14 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable) \l qCWarning(), \l qCCritical() macros. */ +/*! + \fn const QLoggingCategory &QLoggingCategory::operator()() const + + Returns the object itself. This allows both a QLoggingCategory variable, and + a factory method returning a QLoggingCategory, to be used in \l qCDebug(), + \l qCWarning(), \l qCCritical() macros. + */ + /*! Returns a pointer to the global category \c "default" that is used e.g. by qDebug(), qWarning(), qCritical(), qFatal(). diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 7af3af9a24..4aec8e63bf 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -65,6 +65,7 @@ public: // allows usage of both factory method and variable in qCX macros QLoggingCategory &operator()() { return *this; } + const QLoggingCategory &operator()() const { return *this; } static QLoggingCategory *defaultCategory(); diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index 47a5d6044e..b0d7a76f0f 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -428,6 +428,8 @@ private slots: QCOMPARE(logMessage, QString()); qCDebug(TST_LOG, "Check debug with no filter active"); QCOMPARE(logMessage, QString()); + qCDebug(TST_LOG(), "Check debug with no filter active"); + QCOMPARE(logMessage, QString()); buf = QStringLiteral("tst.log.warning: Check warning with no filter active"); qCWarning(TST_LOG) << "Check warning with no filter active"; QCOMPARE(logMessage, buf); -- cgit v1.2.3