QLoggingCategory: Deprecate non-static, non-forward-declared categories

Qt-internal logging categories should either be static or declared in a
header and therefore shared between multiple translation units. This way
we minimize the number of exposed symbols. We want to minimize the
number of exposed symbols in order to reduce the chance of name clashes.

In the same vein, when exporting a Qt-internal logging category it
should be declared explicitly as Qt-internal. The code importing it may
not be a Qt library after all.

Task-number: QTBUG-67692
Change-Id: If1c045471fe52226a34cc94a5fe9b0c9a2de56b5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ulf Hermann 2024-06-12 09:52:27 +02:00
parent e763177209
commit d1213157df
2 changed files with 8 additions and 1 deletions

View File

@ -113,7 +113,10 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable
using QtPrivateLogging::name;
#define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, export_macro) \
namespace QtPrivateLogging { export_macro const QLoggingCategory &name(); } \
namespace QtPrivateLogging { \
Q_DECL_DEPRECATED_X("Use QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in Qt") \
export_macro const QLoggingCategory &name(); \
} \
using QtPrivateLogging::name;
#define Q_LOGGING_CATEGORY_IMPL(name, ...) \
@ -134,6 +137,9 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable
#define Q_LOGGING_CATEGORY(name, ...) \
namespace QtPrivateLogging { Q_LOGGING_CATEGORY_IMPL(name, __VA_ARGS__) } \
Q_WEAK_OVERLOAD \
Q_DECL_DEPRECATED_X("Use Q_STATIC_LOGGING_CATEGORY or add " \
"either Q_DECLARE_LOGGING_CATEGORY or " \
"QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in a header") \
const QLoggingCategory &name() { return QtPrivateLogging::name(); }
#endif

View File

@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE_IMPL(name, env, categoryName) \
} \
Q_WEAK_OVERLOAD \
Q_DECL_DEPRECATED_X("Logging categories should either be static or declared in a header") \
const QLoggingCategory &name() { return QtPrivateLogging::name(); }
#endif