summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobjectdefs.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-03 08:28:30 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-11 20:15:48 +0100
commitefe411b8b70fac35eee65371f95636880baee9d3 (patch)
treebefd4f6c45737c683c5c71153960867592ae2601 /src/corelib/kernel/qobjectdefs.h
parentb0d106267c773a177bc3316e387261f2696692b5 (diff)
qobjectdefs.h: DRY the SIGNAL/SLOT macros
Factor common code into a separate macro to DRY. The immediate paractical consequence is that we now have a way to reliably get a const char[] from the SIGNAL or SLOT macros, e.g. for storing in a QOffsetStringArray, without causing compile errors in debug mode or running the danger of causing runtime initialization via qFlagLocation, which is of limited value in this circumstance, anyway, because qFlagLocation only stores the last two strings. Pick-to: 6.3 Change-Id: I67401858e94eedc1200fdd08e695fd56d10f8560 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobjectdefs.h')
-rw-r--r--src/corelib/kernel/qobjectdefs.h39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 6ffdb2a5de..3033f7b763 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -72,24 +72,27 @@ class QString;
Q_CORE_EXPORT const char *qFlagLocation(const char *method);
#ifndef QT_NO_META_MACROS
-#ifndef QT_NO_DEBUG
-# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
-# ifndef QT_NO_KEYWORDS
-# define METHOD(a) qFlagLocation("0"#a QLOCATION)
+# define QMETHOD_CODE 0 // member type codes
+# define QSLOT_CODE 1
+# define QSIGNAL_CODE 2
+# define QT_PREFIX_CODE(code, a) QT_STRINGIFY(code) #a
+# define QT_STRINGIFY_METHOD(a) QT_PREFIX_CODE(QMETHOD_CODE, a)
+# define QT_STRINGIFY_SLOT(a) QT_PREFIX_CODE(QSLOT_CODE, a)
+# define QT_STRINGIFY_SIGNAL(a) QT_PREFIX_CODE(QSIGNAL_CODE, a)
+# ifndef QT_NO_DEBUG
+# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
+# ifndef QT_NO_KEYWORDS
+# define METHOD(a) qFlagLocation(QT_STRINGIFY_METHOD(a) QLOCATION)
+# endif
+# define SLOT(a) qFlagLocation(QT_STRINGIFY_SLOT(a) QLOCATION)
+# define SIGNAL(a) qFlagLocation(QT_STRINGIFY_SIGNAL(a) QLOCATION)
+# else
+# ifndef QT_NO_KEYWORDS
+# define METHOD(a) QT_STRINGIFY_METHOD(a)
+# endif
+# define SLOT(a) QT_STRINGIFY_SLOT(a)
+# define SIGNAL(a) QT_STRINGIFY_SIGNAL(a)
# endif
-# define SLOT(a) qFlagLocation("1"#a QLOCATION)
-# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
-#else
-# ifndef QT_NO_KEYWORDS
-# define METHOD(a) "0"#a
-# endif
-# define SLOT(a) "1"#a
-# define SIGNAL(a) "2"#a
-#endif
-
-#define QMETHOD_CODE 0 // member type codes
-#define QSLOT_CODE 1
-#define QSIGNAL_CODE 2
#endif // QT_NO_META_MACROS
#define Q_ARG(type, data) QArgument<type >(#type, data)