summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-06-17 16:44:21 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-06-27 00:12:56 +0200
commit7466422e9ce964553dd09fce9f48437af7ec76c8 (patch)
treef727125120f9ff25fb72633be5645c6742b6f6c5 /src/corelib/io
parent821aa1ff095ae66a89eb8725650dccac363f06ad (diff)
Add a way to declare _exported_ logging categories
If a library declares a logging category that needs to be used by clients (e.g. via inline methods, macros, etc.), then the logging category function generated by Q_DECLARE_LOGGING_CATEGORY has to be exported. We've seen this problem with Q_NAMESPACE, Q_GADGET, etc.: these macros also declare functions or objects that in some cases need to be exported. And precisely like Q_NAMESPACE, Q_GADGET, etc., people end up relying on the implementation details of Q_DECLARE_LOGGING_CATEGORY (specifically, what does it expand to) in order to place the export directives in the right place. Introduce a more robust solution and apply it around qtbase. Cleanup some minor code as a drive-by (remove `extern` and useless semicolons). [ChangeLog][QtCore][QLoggingCategory] Added the Q_DECLARE_EXPORTED_LOGGING_CATEGORY macro, in order to allow dynamic libraries to declare a logging category that can be then used by client code. Change-Id: I18f40cc937cfe8277b8d62ebc824c27a0773de04 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qloggingcategory.cpp30
-rw-r--r--src/corelib/io/qloggingcategory.h5
2 files changed, 32 insertions, 3 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 08b7b2d584..201a50317b 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -51,6 +51,9 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\snippet qloggingcategory/main.cpp 1
+ There is also the Q_DECLARE_EXPORTED_LOGGING_CATEGORY() macro in
+ order to use a logging category across library boundaries.
+
Category names are free text; to configure categories using \l{Logging Rules}, their
names should follow this convention:
\list
@@ -574,7 +577,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
*/
/*!
\macro Q_DECLARE_LOGGING_CATEGORY(name)
- \sa Q_LOGGING_CATEGORY()
+ \sa Q_LOGGING_CATEGORY(), Q_DECLARE_EXPORTED_LOGGING_CATEGORY()
\relates QLoggingCategory
\since 5.2
@@ -585,8 +588,31 @@ void QLoggingCategory::setFilterRules(const QString &rules)
*/
/*!
+ \macro Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, EXPORT_MACRO)
+ \sa Q_LOGGING_CATEGORY(), Q_DECLARE_LOGGING_CATEGORY()
+ \relates QLoggingCategory
+ \since 6.5
+
+ Declares a logging category \a name. The macro can be used to declare
+ a common logging category shared in different parts of the program.
+
+ This works exactly like Q_DECLARE_LOGGING_CATEGORY(). However,
+ the logging category declared by this macro is additionally
+ qualified with \a EXPORT_MACRO. This is useful if the logging
+ category needs to be exported from a dynamic library.
+
+ For example:
+
+ \code
+ Q_DECLARE_EXPORTED_LOGGING_CATEGORY("lib.core", LIB_EXPORT_MACRO)
+ \endcode
+
+ This macro must be used outside of a class or function.
+*/
+
+/*!
\macro Q_LOGGING_CATEGORY(name, string)
- \sa Q_DECLARE_LOGGING_CATEGORY()
+ \sa Q_DECLARE_LOGGING_CATEGORY(), Q_DECLARE_EXPORTED_LOGGING_CATEGORY()
\relates QLoggingCategory
\since 5.2
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index 60773bd2a9..ae8425142a 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -118,8 +118,11 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable
#endif
} // unnamed namespace
+#define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, ...) \
+ __VA_ARGS__ const QLoggingCategory &name();
+
#define Q_DECLARE_LOGGING_CATEGORY(name) \
- extern const QLoggingCategory &name();
+ Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name)
#define Q_LOGGING_CATEGORY(name, ...) \
const QLoggingCategory &name() \