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 <alexander.blasche@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Kai Koehne 2014-02-14 13:36:38 +01:00 committed by The Qt Project
parent 0bb6b65c56
commit c9cdbcb12f
3 changed files with 11 additions and 0 deletions

View File

@ -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().

View File

@ -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();

View File

@ -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);