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 <ritt.ks@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Kai Koehne 2014-01-10 15:42:19 +01:00 committed by The Qt Project
parent b648f11227
commit 85e576535c
3 changed files with 5 additions and 5 deletions

View File

@ -54,5 +54,5 @@
//! [1] //! [1]
//! [2] //! [2]
QLoggingCategory &category(); const QLoggingCategory &category();
//! [2] //! [2]

View File

@ -100,7 +100,7 @@ public:
void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void critical(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(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); void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);

View File

@ -84,13 +84,13 @@ private:
}; };
#define Q_DECLARE_LOGGING_CATEGORY(name) \ #define Q_DECLARE_LOGGING_CATEGORY(name) \
extern QLoggingCategory &name(); extern const QLoggingCategory &name();
// relies on QLoggingCategory(QString) being thread safe! // relies on QLoggingCategory(QString) being thread safe!
#define Q_LOGGING_CATEGORY(name, string) \ #define Q_LOGGING_CATEGORY(name, string) \
QLoggingCategory &name() \ const QLoggingCategory &name() \
{ \ { \
static QLoggingCategory category(string); \ static const QLoggingCategory category(string); \
return category; \ return category; \
} }