From 85e576535c9c39756ecaddefa245f71fb35b8589 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 10 Jan 2014 15:42:19 +0100 Subject: Let Q_DECLARE_LOGGING_CATEGORY and Q_LOGGING_CATEGORY return a const reference In general QLoggingCategory should be treated as a const object that's configured by the backend. The only legitimate place where user code should call setEnabled is in a CategoryFilter ... [ChangeLog][QtCore][Logging] Make Q_LOGGING_CATEGORY and Q_DECLARE_LOGGING_CATEGORY return a const object. Change-Id: I6140442ab48286e05cd3b55064a502bbe6dfb16a Reviewed-by: Konstantin Ritt Reviewed-by: Thiago Macieira --- src/corelib/doc/snippets/code/qlogging/qlogging.cpp | 2 +- src/corelib/global/qlogging.h | 2 +- src/corelib/io/qloggingcategory.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp index d3b9e1fd14..ff5ce23eff 100644 --- a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp +++ b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp @@ -54,5 +54,5 @@ //! [1] //! [2] - QLoggingCategory &category(); + const QLoggingCategory &category(); //! [2] diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 6d651ee8a0..6ebffa3ba1 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -100,7 +100,7 @@ public: void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); - typedef QLoggingCategory &(*CategoryFunction)(); + typedef const QLoggingCategory &(*CategoryFunction)(); void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4); void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4); diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 37735908a1..e701f93472 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -84,13 +84,13 @@ private: }; #define Q_DECLARE_LOGGING_CATEGORY(name) \ - extern QLoggingCategory &name(); + extern const QLoggingCategory &name(); // relies on QLoggingCategory(QString) being thread safe! #define Q_LOGGING_CATEGORY(name, string) \ - QLoggingCategory &name() \ + const QLoggingCategory &name() \ { \ - static QLoggingCategory category(string); \ + static const QLoggingCategory category(string); \ return category; \ } -- cgit v1.2.3