Long live Q_GADGET_EXPORT!

Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.

Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).

[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).

Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Marc Mutz 2021-11-22 10:30:04 +01:00
parent cf2336ae6e
commit a0f9aef11b
11 changed files with 270 additions and 193 deletions

View File

@ -36,7 +36,7 @@ function(qt_enable_autogen_tool target tool enable)
# that the moc scanner has to look for. Inform the CMake moc scanner about it.
if(tool STREQUAL "moc" AND enable)
set_target_properties("${target}" PROPERTIES
AUTOMOC_MACRO_NAMES "Q_OBJECT;Q_GADGET;Q_NAMESPACE;Q_NAMESPACE_EXPORT;Q_ENUM_NS")
AUTOMOC_MACRO_NAMES "Q_OBJECT;Q_GADGET;Q_GADGET_EXPORT;Q_NAMESPACE;Q_NAMESPACE_EXPORT;Q_ENUM_NS")
if (TARGET Qt::Platform)
get_target_property(_abi_tag Qt::Platform qt_libcpp_abi_tag)

View File

@ -92,6 +92,7 @@ Cpp.ignoretokens += \
Q_EXPORT_PLUGIN \
Q_EXPORT_PLUGIN2 \
Q_GADGET \
Q_GADGET_EXPORT \
Q_GFX_INLINE \
Q_GUI_EXPORT \
Q_GUI_EXPORT_INLINE \

View File

@ -927,6 +927,7 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
enum Keywords {
Q_OBJECT_Keyword,
Q_GADGET_Keyword,
Q_GADGET_EXPORT_Keyword,
Q_NAMESPACE_Keyword,
Q_NAMESPACE_EXPORT_Keyword,
@ -935,12 +936,14 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
static const char keywords[][19] = {
"Q_OBJECT",
"Q_GADGET",
"Q_GADGET_EXPORT",
"Q_NAMESPACE",
"Q_NAMESPACE_EXPORT",
};
static_assert(std::size(keywords) == NumKeywords);
bool ignore[NumKeywords] = {};
/* qmake ignore Q_GADGET */
/* qmake ignore Q_GADGET_EXPORT */
/* qmake ignore Q_OBJECT */
/* qmake ignore Q_NAMESPACE */
/* qmake ignore Q_NAMESPACE_EXPORT */

View File

@ -20,7 +20,7 @@ if (NOT QT_NO_CREATE_TARGETS)
set_property(TARGET @QT_CMAKE_EXPORT_NAMESPACE@::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)
endif()
set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_GADGET_EXPORT" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
# install layout information, following what qmake -query provides
get_filename_component(QT@PROJECT_VERSION_MAJOR@_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../@QT_INVERSE_CONFIG_INSTALL_DIR@ ABSOLUTE)

View File

@ -4400,8 +4400,8 @@ QDebug operator<<(QDebug dbg, const QObject *o)
\since 5.5
This macro registers an enum type with the meta-object system.
It must be placed after the enum declaration in a class that has the Q_OBJECT or the
Q_GADGET macro. For namespaces use \l Q_ENUM_NS() instead.
It must be placed after the enum declaration in a class that has the Q_OBJECT,
Q_GADGET or Q_GADGET_EXPORT macro. For namespaces use \l Q_ENUM_NS() instead.
For example:
@ -4519,7 +4519,7 @@ QDebug operator<<(QDebug dbg, const QObject *o)
\snippet signalsandslots/signalsandslots.h 3
\note This macro requires the class to be a subclass of QObject. Use
Q_GADGET instead of Q_OBJECT to enable the meta object system's support
Q_GADGET or Q_GADGET_EXPORT instead of Q_OBJECT to enable the meta object system's support
for enums in a class that is not a QObject subclass.
\sa {Meta-Object System}, {Signals and Slots}, {Qt's Property System}
@ -4540,6 +4540,33 @@ QDebug operator<<(QDebug dbg, const QObject *o)
Q_GADGET makes a class member, \c{staticMetaObject}, available.
\c{staticMetaObject} is of type QMetaObject and provides access to the
enums declared with Q_ENUMS.
\sa Q_GADGET_EXPORT
*/
/*!
\macro Q_GADGET_EXPORT(EXPORT_MACRO)
\relates QObject
\since 6.3
The Q_GADGET_EXPORT macro works exactly like the Q_GADGET macro.
However, the \c{staticMetaObject} variable that is made available (see
Q_GADGET) is declared with the supplied \a EXPORT_MACRO qualifier. This is
useful if the object needs to be exported from a dynamic library, but the
enclosing class as a whole should not be (e.g. because it consists of mostly
inline functions).
For example:
\code
class Point {
Q_GADGET_EXPORT(EXPORT_MACRO)
Q_PROPERTY(int x MEMBER x)
Q_PROPERTY(int y MEMBER y)
~~~
\endcode
\sa Q_GADGET, {Creating Shared Libraries}
*/
/*!

View File

@ -171,10 +171,10 @@ private: \
#define Q_OBJECT_FAKE Q_OBJECT QT_ANNOTATE_CLASS(qt_fake, "")
#ifndef QT_NO_META_MACROS
/* qmake ignore Q_GADGET */
#define Q_GADGET \
/* qmake ignore Q_GADGET_EXPORT */
#define Q_GADGET_EXPORT(...) \
public: \
static const QMetaObject staticMetaObject; \
static __VA_ARGS__ const QMetaObject staticMetaObject; \
void qt_check_for_QGADGET_macro(); \
typedef void QtGadgetHelper; \
private: \
@ -185,7 +185,10 @@ private: \
QT_ANNOTATE_CLASS(qt_qgadget, "") \
/*end*/
/* qmake ignore Q_NAMESPACE_EXPORT */
/* qmake ignore Q_GADGET */
#define Q_GADGET Q_GADGET_EXPORT()
/* qmake ignore Q_NAMESPACE_EXPORT */
#define Q_NAMESPACE_EXPORT(...) \
extern __VA_ARGS__ const QMetaObject staticMetaObject; \
QT_ANNOTATE_CLASS(qt_qnamespace, "") \

View File

@ -30,12 +30,12 @@
// DO NOT EDIT.
static const short keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,579,576,0,0,0,0,0,
{0,0,0,0,0,0,0,0,0,586,583,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
579,252,577,580,8,38,239,578,25,26,236,234,30,235,27,237,
586,252,584,587,8,38,239,585,25,26,236,234,30,235,27,237,
22,22,22,22,22,22,22,22,22,22,34,41,23,39,24,43,
0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,21,8,8,8,8,8,8,8,8,8,31,582,32,238,8,
8,21,8,8,8,8,8,8,8,8,8,31,589,32,238,8,
0,1,2,3,4,5,6,7,8,9,8,8,10,11,12,13,
14,8,15,16,17,18,19,20,8,8,8,36,245,37,248,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -116,7 +116,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,290,222,0,0,497,0,0,0,
0,0,0,0,0,0,0,0,290,222,0,0,504,0,0,0,
0,0,0,0,55,0,0,330,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -155,7 +155,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,521,0,0,0,0,0,0,0,0,0,0,357,
0,0,0,0,528,0,0,0,0,0,0,0,0,0,0,357,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -177,7 +177,7 @@ static const short keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,42,0,0,0,28,0,
585,585,585,585,585,585,585,585,585,585,0,0,0,0,0,0,
592,592,592,592,592,592,592,592,592,592,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -336,7 +336,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,584,0,0,0,0,583,
0,0,0,0,0,0,0,0,0,0,591,0,0,0,0,590,
0,0,0,0,0,0,0,0,0,0,0,0,0,258,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -372,29 +372,29 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,494,0,0,0,300,0,0,0,0,0,0,0,0,0,0,
0,501,0,0,0,300,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,475,424,408,416,380,0,484,0,0,0,565,364,358,
386,0,557,472,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,482,431,415,423,380,0,491,0,0,0,572,364,358,
393,0,564,479,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,394,0,0,0,
0,0,387,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,401,0,0,0,
0,0,394,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,511,0,0,0,0,0,388,
0,0,0,0,0,0,0,0,0,518,0,0,0,0,0,395,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
@ -403,7 +403,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,412,0,0,0,0,0,0,0,0,0,0,0,413,
0,0,0,419,0,0,0,0,0,0,0,0,0,0,0,420,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -411,14 +411,14 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,420,0,0,0,0,0,0,0,0,0,0,0,421,
0,0,0,427,0,0,0,0,0,0,0,0,0,0,0,428,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,454,432,0,0,437,0,0,0,446,0,0,
0,0,0,0,0,461,439,0,0,444,0,0,0,453,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
@ -426,7 +426,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,540,0,473,0,0,0,501,0,0,507,0,0,0,
0,0,0,547,0,480,0,0,0,508,0,0,514,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
@ -435,7 +435,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,486,0,533,0,0,0,0,0,0,0,0,0,
0,0,0,0,493,0,540,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -443,7 +443,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
549,0,0,517,0,0,0,0,0,0,0,0,0,0,0,0,
556,0,0,524,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
@ -841,202 +841,209 @@ static const struct
{CHARACTER, 0, 71, 383, CHARACTER},
{CHARACTER, 0, 69, 384, CHARACTER},
{CHARACTER, 0, 84, 385, CHARACTER},
{Q_GADGET_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 44, 0, 0, CHARACTER},
{CHARACTER, 45, 0, 0, CHARACTER},
{Q_GADGET_TOKEN, 0, 95, 386, CHARACTER},
{CHARACTER, 0, 69, 387, CHARACTER},
{CHARACTER, 0, 88, 388, CHARACTER},
{CHARACTER, 0, 80, 389, CHARACTER},
{CHARACTER, 0, 69, 390, CHARACTER},
{CHARACTER, 0, 79, 390, CHARACTER},
{CHARACTER, 0, 82, 391, CHARACTER},
{CHARACTER, 0, 84, 392, CHARACTER},
{CHARACTER, 0, 89, 393, CHARACTER},
{Q_GADGET_EXPORT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 44, 0, 0, CHARACTER},
{CHARACTER, 45, 0, 0, CHARACTER},
{CHARACTER, 0, 80, 396, CHARACTER},
{CHARACTER, 0, 69, 397, CHARACTER},
{CHARACTER, 0, 82, 398, CHARACTER},
{CHARACTER, 0, 84, 399, CHARACTER},
{CHARACTER, 0, 89, 400, CHARACTER},
{Q_PROPERTY_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 85, 395, CHARACTER},
{CHARACTER, 0, 71, 396, CHARACTER},
{CHARACTER, 0, 73, 397, CHARACTER},
{CHARACTER, 0, 78, 398, CHARACTER},
{CHARACTER, 0, 95, 399, CHARACTER},
{CHARACTER, 0, 77, 400, CHARACTER},
{CHARACTER, 0, 69, 401, CHARACTER},
{CHARACTER, 0, 84, 402, CHARACTER},
{CHARACTER, 0, 65, 403, CHARACTER},
{CHARACTER, 0, 68, 404, CHARACTER},
{CHARACTER, 0, 65, 405, CHARACTER},
{CHARACTER, 0, 84, 406, CHARACTER},
{CHARACTER, 0, 65, 407, CHARACTER},
{CHARACTER, 0, 85, 402, CHARACTER},
{CHARACTER, 0, 71, 403, CHARACTER},
{CHARACTER, 0, 73, 404, CHARACTER},
{CHARACTER, 0, 78, 405, CHARACTER},
{CHARACTER, 0, 95, 406, CHARACTER},
{CHARACTER, 0, 77, 407, CHARACTER},
{CHARACTER, 0, 69, 408, CHARACTER},
{CHARACTER, 0, 84, 409, CHARACTER},
{CHARACTER, 0, 65, 410, CHARACTER},
{CHARACTER, 0, 68, 411, CHARACTER},
{CHARACTER, 0, 65, 412, CHARACTER},
{CHARACTER, 0, 84, 413, CHARACTER},
{CHARACTER, 0, 65, 414, CHARACTER},
{Q_PLUGIN_METADATA_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 409, CHARACTER},
{CHARACTER, 0, 85, 410, CHARACTER},
{CHARACTER, 0, 77, 411, CHARACTER},
{CHARACTER, 0, 78, 416, CHARACTER},
{CHARACTER, 0, 85, 417, CHARACTER},
{CHARACTER, 0, 77, 418, CHARACTER},
{Q_ENUM_TOKEN, 46, 0, 0, CHARACTER},
{Q_ENUMS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 414, CHARACTER},
{CHARACTER, 0, 83, 415, CHARACTER},
{CHARACTER, 0, 78, 421, CHARACTER},
{CHARACTER, 0, 83, 422, CHARACTER},
{Q_ENUM_NS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 417, CHARACTER},
{CHARACTER, 0, 65, 418, CHARACTER},
{CHARACTER, 0, 71, 419, CHARACTER},
{CHARACTER, 0, 76, 424, CHARACTER},
{CHARACTER, 0, 65, 425, CHARACTER},
{CHARACTER, 0, 71, 426, CHARACTER},
{Q_FLAG_TOKEN, 47, 0, 0, CHARACTER},
{Q_FLAGS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 422, CHARACTER},
{CHARACTER, 0, 83, 423, CHARACTER},
{CHARACTER, 0, 78, 429, CHARACTER},
{CHARACTER, 0, 83, 430, CHARACTER},
{Q_FLAG_NS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 425, CHARACTER},
{CHARACTER, 0, 67, 426, CHARACTER},
{CHARACTER, 0, 76, 427, CHARACTER},
{CHARACTER, 0, 65, 428, CHARACTER},
{CHARACTER, 0, 82, 429, CHARACTER},
{CHARACTER, 0, 69, 430, CHARACTER},
{CHARACTER, 0, 95, 431, CHARACTER},
{CHARACTER, 0, 69, 432, CHARACTER},
{CHARACTER, 0, 67, 433, CHARACTER},
{CHARACTER, 0, 76, 434, CHARACTER},
{CHARACTER, 0, 65, 435, CHARACTER},
{CHARACTER, 0, 82, 436, CHARACTER},
{CHARACTER, 0, 69, 437, CHARACTER},
{CHARACTER, 0, 95, 438, CHARACTER},
{CHARACTER, 48, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 433, CHARACTER},
{CHARACTER, 0, 65, 434, CHARACTER},
{CHARACTER, 0, 71, 435, CHARACTER},
{CHARACTER, 0, 83, 436, CHARACTER},
{CHARACTER, 0, 76, 440, CHARACTER},
{CHARACTER, 0, 65, 441, CHARACTER},
{CHARACTER, 0, 71, 442, CHARACTER},
{CHARACTER, 0, 83, 443, CHARACTER},
{Q_DECLARE_FLAGS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 438, CHARACTER},
{CHARACTER, 0, 84, 439, CHARACTER},
{CHARACTER, 0, 69, 440, CHARACTER},
{CHARACTER, 0, 82, 441, CHARACTER},
{CHARACTER, 0, 70, 442, CHARACTER},
{CHARACTER, 0, 65, 443, CHARACTER},
{CHARACTER, 0, 67, 444, CHARACTER},
{CHARACTER, 0, 69, 445, CHARACTER},
{Q_DECLARE_INTERFACE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 445, CHARACTER},
{CHARACTER, 0, 84, 446, CHARACTER},
{CHARACTER, 0, 69, 447, CHARACTER},
{CHARACTER, 0, 84, 448, CHARACTER},
{CHARACTER, 0, 65, 449, CHARACTER},
{CHARACTER, 0, 84, 450, CHARACTER},
{CHARACTER, 0, 89, 451, CHARACTER},
{CHARACTER, 0, 80, 452, CHARACTER},
{CHARACTER, 0, 69, 453, CHARACTER},
{CHARACTER, 0, 82, 448, CHARACTER},
{CHARACTER, 0, 70, 449, CHARACTER},
{CHARACTER, 0, 65, 450, CHARACTER},
{CHARACTER, 0, 67, 451, CHARACTER},
{CHARACTER, 0, 69, 452, CHARACTER},
{Q_DECLARE_INTERFACE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 454, CHARACTER},
{CHARACTER, 0, 84, 455, CHARACTER},
{CHARACTER, 0, 65, 456, CHARACTER},
{CHARACTER, 0, 84, 457, CHARACTER},
{CHARACTER, 0, 89, 458, CHARACTER},
{CHARACTER, 0, 80, 459, CHARACTER},
{CHARACTER, 0, 69, 460, CHARACTER},
{Q_DECLARE_METATYPE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 88, 455, CHARACTER},
{CHARACTER, 0, 84, 456, CHARACTER},
{CHARACTER, 0, 69, 457, CHARACTER},
{CHARACTER, 0, 78, 458, CHARACTER},
{CHARACTER, 0, 83, 459, CHARACTER},
{CHARACTER, 0, 73, 460, CHARACTER},
{CHARACTER, 0, 79, 461, CHARACTER},
{CHARACTER, 0, 78, 462, CHARACTER},
{CHARACTER, 0, 95, 463, CHARACTER},
{CHARACTER, 0, 73, 464, CHARACTER},
{CHARACTER, 0, 88, 462, CHARACTER},
{CHARACTER, 0, 84, 463, CHARACTER},
{CHARACTER, 0, 69, 464, CHARACTER},
{CHARACTER, 0, 78, 465, CHARACTER},
{CHARACTER, 0, 84, 466, CHARACTER},
{CHARACTER, 0, 69, 467, CHARACTER},
{CHARACTER, 0, 82, 468, CHARACTER},
{CHARACTER, 0, 70, 469, CHARACTER},
{CHARACTER, 0, 65, 470, CHARACTER},
{CHARACTER, 0, 67, 471, CHARACTER},
{CHARACTER, 0, 69, 445, CHARACTER},
{CHARACTER, 49, 0, 0, CHARACTER},
{CHARACTER, 0, 84, 474, CHARACTER},
{CHARACTER, 0, 83, 420, CHARACTER},
{CHARACTER, 0, 76, 476, CHARACTER},
{CHARACTER, 0, 83, 466, CHARACTER},
{CHARACTER, 0, 73, 467, CHARACTER},
{CHARACTER, 0, 79, 468, CHARACTER},
{CHARACTER, 0, 78, 469, CHARACTER},
{CHARACTER, 0, 95, 470, CHARACTER},
{CHARACTER, 0, 73, 471, CHARACTER},
{CHARACTER, 0, 78, 472, CHARACTER},
{CHARACTER, 0, 84, 473, CHARACTER},
{CHARACTER, 0, 69, 474, CHARACTER},
{CHARACTER, 0, 82, 475, CHARACTER},
{CHARACTER, 0, 70, 476, CHARACTER},
{CHARACTER, 0, 65, 477, CHARACTER},
{CHARACTER, 0, 83, 478, CHARACTER},
{CHARACTER, 0, 83, 479, CHARACTER},
{CHARACTER, 0, 73, 480, CHARACTER},
{CHARACTER, 0, 78, 481, CHARACTER},
{CHARACTER, 0, 70, 482, CHARACTER},
{CHARACTER, 0, 79, 483, CHARACTER},
{Q_CLASSINFO_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 485, CHARACTER},
{CHARACTER, 50, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 487, CHARACTER},
{CHARACTER, 0, 82, 488, CHARACTER},
{CHARACTER, 0, 67, 478, CHARACTER},
{CHARACTER, 0, 69, 452, CHARACTER},
{CHARACTER, 49, 0, 0, CHARACTER},
{CHARACTER, 0, 84, 481, CHARACTER},
{CHARACTER, 0, 83, 427, CHARACTER},
{CHARACTER, 0, 76, 483, CHARACTER},
{CHARACTER, 0, 65, 484, CHARACTER},
{CHARACTER, 0, 83, 485, CHARACTER},
{CHARACTER, 0, 83, 486, CHARACTER},
{CHARACTER, 0, 73, 487, CHARACTER},
{CHARACTER, 0, 78, 488, CHARACTER},
{CHARACTER, 0, 70, 489, CHARACTER},
{CHARACTER, 0, 65, 490, CHARACTER},
{CHARACTER, 0, 67, 491, CHARACTER},
{CHARACTER, 0, 69, 492, CHARACTER},
{CHARACTER, 0, 83, 493, CHARACTER},
{CHARACTER, 0, 79, 490, CHARACTER},
{Q_CLASSINFO_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 492, CHARACTER},
{CHARACTER, 50, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 494, CHARACTER},
{CHARACTER, 0, 82, 495, CHARACTER},
{CHARACTER, 0, 70, 496, CHARACTER},
{CHARACTER, 0, 65, 497, CHARACTER},
{CHARACTER, 0, 67, 498, CHARACTER},
{CHARACTER, 0, 69, 499, CHARACTER},
{CHARACTER, 0, 83, 500, CHARACTER},
{Q_INTERFACES_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 108, 495, CHARACTER},
{CHARACTER, 0, 115, 496, CHARACTER},
{CHARACTER, 0, 108, 502, CHARACTER},
{CHARACTER, 0, 115, 503, CHARACTER},
{SIGNALS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 111, 498, CHARACTER},
{CHARACTER, 0, 116, 499, CHARACTER},
{CHARACTER, 0, 115, 500, CHARACTER},
{CHARACTER, 0, 111, 505, CHARACTER},
{CHARACTER, 0, 116, 506, CHARACTER},
{CHARACTER, 0, 115, 507, CHARACTER},
{SLOTS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 71, 502, CHARACTER},
{CHARACTER, 0, 78, 503, CHARACTER},
{CHARACTER, 0, 65, 504, CHARACTER},
{CHARACTER, 0, 76, 505, CHARACTER},
{Q_SIGNAL_TOKEN, 0, 83, 506, CHARACTER},
{CHARACTER, 0, 71, 509, CHARACTER},
{CHARACTER, 0, 78, 510, CHARACTER},
{CHARACTER, 0, 65, 511, CHARACTER},
{CHARACTER, 0, 76, 512, CHARACTER},
{Q_SIGNAL_TOKEN, 0, 83, 513, CHARACTER},
{Q_SIGNALS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 508, CHARACTER},
{CHARACTER, 0, 84, 509, CHARACTER},
{Q_SLOT_TOKEN, 0, 83, 510, CHARACTER},
{CHARACTER, 0, 79, 515, CHARACTER},
{CHARACTER, 0, 84, 516, CHARACTER},
{Q_SLOT_TOKEN, 0, 83, 517, CHARACTER},
{Q_SLOTS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 86, 512, CHARACTER},
{CHARACTER, 0, 65, 513, CHARACTER},
{CHARACTER, 0, 84, 514, CHARACTER},
{CHARACTER, 0, 69, 515, CHARACTER},
{CHARACTER, 0, 95, 516, CHARACTER},
{CHARACTER, 0, 86, 519, CHARACTER},
{CHARACTER, 0, 65, 520, CHARACTER},
{CHARACTER, 0, 84, 521, CHARACTER},
{CHARACTER, 0, 69, 522, CHARACTER},
{CHARACTER, 0, 95, 523, CHARACTER},
{CHARACTER, 51, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 518, CHARACTER},
{CHARACTER, 0, 79, 519, CHARACTER},
{CHARACTER, 0, 84, 520, CHARACTER},
{CHARACTER, 0, 76, 525, CHARACTER},
{CHARACTER, 0, 79, 526, CHARACTER},
{CHARACTER, 0, 84, 527, CHARACTER},
{Q_PRIVATE_SLOT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 95, 522, CHARACTER},
{CHARACTER, 0, 77, 523, CHARACTER},
{CHARACTER, 0, 79, 524, CHARACTER},
{CHARACTER, 0, 67, 525, CHARACTER},
{CHARACTER, 0, 95, 526, CHARACTER},
{CHARACTER, 0, 67, 527, CHARACTER},
{CHARACTER, 0, 79, 528, CHARACTER},
{CHARACTER, 0, 77, 529, CHARACTER},
{CHARACTER, 0, 80, 530, CHARACTER},
{CHARACTER, 0, 65, 531, CHARACTER},
{CHARACTER, 0, 84, 532, CHARACTER},
{CHARACTER, 0, 95, 529, CHARACTER},
{CHARACTER, 0, 77, 530, CHARACTER},
{CHARACTER, 0, 79, 531, CHARACTER},
{CHARACTER, 0, 67, 532, CHARACTER},
{CHARACTER, 0, 95, 533, CHARACTER},
{CHARACTER, 0, 67, 534, CHARACTER},
{CHARACTER, 0, 79, 535, CHARACTER},
{CHARACTER, 0, 77, 536, CHARACTER},
{CHARACTER, 0, 80, 537, CHARACTER},
{CHARACTER, 0, 65, 538, CHARACTER},
{CHARACTER, 0, 84, 539, CHARACTER},
{Q_MOC_COMPAT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 534, CHARACTER},
{CHARACTER, 0, 75, 535, CHARACTER},
{CHARACTER, 0, 65, 536, CHARACTER},
{CHARACTER, 0, 66, 537, CHARACTER},
{CHARACTER, 0, 76, 538, CHARACTER},
{CHARACTER, 0, 69, 539, CHARACTER},
{CHARACTER, 0, 79, 541, CHARACTER},
{CHARACTER, 0, 75, 542, CHARACTER},
{CHARACTER, 0, 65, 543, CHARACTER},
{CHARACTER, 0, 66, 544, CHARACTER},
{CHARACTER, 0, 76, 545, CHARACTER},
{CHARACTER, 0, 69, 546, CHARACTER},
{Q_INVOKABLE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 82, 541, CHARACTER},
{CHARACTER, 0, 73, 542, CHARACTER},
{CHARACTER, 0, 80, 543, CHARACTER},
{CHARACTER, 0, 84, 544, CHARACTER},
{CHARACTER, 0, 65, 545, CHARACTER},
{CHARACTER, 0, 66, 546, CHARACTER},
{CHARACTER, 0, 76, 547, CHARACTER},
{CHARACTER, 0, 69, 548, CHARACTER},
{CHARACTER, 0, 82, 548, CHARACTER},
{CHARACTER, 0, 73, 549, CHARACTER},
{CHARACTER, 0, 80, 550, CHARACTER},
{CHARACTER, 0, 84, 551, CHARACTER},
{CHARACTER, 0, 65, 552, CHARACTER},
{CHARACTER, 0, 66, 553, CHARACTER},
{CHARACTER, 0, 76, 554, CHARACTER},
{CHARACTER, 0, 69, 555, CHARACTER},
{Q_SCRIPTABLE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 82, 550, CHARACTER},
{CHARACTER, 0, 79, 551, CHARACTER},
{CHARACTER, 0, 80, 552, CHARACTER},
{CHARACTER, 0, 69, 553, CHARACTER},
{CHARACTER, 0, 82, 554, CHARACTER},
{CHARACTER, 0, 84, 555, CHARACTER},
{CHARACTER, 0, 89, 556, CHARACTER},
{CHARACTER, 0, 82, 557, CHARACTER},
{CHARACTER, 0, 79, 558, CHARACTER},
{CHARACTER, 0, 80, 559, CHARACTER},
{CHARACTER, 0, 69, 560, CHARACTER},
{CHARACTER, 0, 82, 561, CHARACTER},
{CHARACTER, 0, 84, 562, CHARACTER},
{CHARACTER, 0, 89, 563, CHARACTER},
{Q_PRIVATE_PROPERTY_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 558, CHARACTER},
{CHARACTER, 0, 86, 559, CHARACTER},
{CHARACTER, 0, 73, 560, CHARACTER},
{CHARACTER, 0, 83, 561, CHARACTER},
{CHARACTER, 0, 73, 562, CHARACTER},
{CHARACTER, 0, 79, 563, CHARACTER},
{CHARACTER, 0, 78, 564, CHARACTER},
{Q_REVISION_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 566, CHARACTER},
{CHARACTER, 0, 67, 567, CHARACTER},
{CHARACTER, 0, 95, 568, CHARACTER},
{CHARACTER, 0, 69, 565, CHARACTER},
{CHARACTER, 0, 86, 566, CHARACTER},
{CHARACTER, 0, 73, 567, CHARACTER},
{CHARACTER, 0, 83, 568, CHARACTER},
{CHARACTER, 0, 73, 569, CHARACTER},
{CHARACTER, 0, 78, 570, CHARACTER},
{CHARACTER, 0, 67, 571, CHARACTER},
{CHARACTER, 0, 76, 572, CHARACTER},
{CHARACTER, 0, 85, 573, CHARACTER},
{CHARACTER, 0, 68, 574, CHARACTER},
{CHARACTER, 0, 69, 575, CHARACTER},
{CHARACTER, 0, 79, 570, CHARACTER},
{CHARACTER, 0, 78, 571, CHARACTER},
{Q_REVISION_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 573, CHARACTER},
{CHARACTER, 0, 67, 574, CHARACTER},
{CHARACTER, 0, 95, 575, CHARACTER},
{CHARACTER, 0, 73, 576, CHARACTER},
{CHARACTER, 0, 78, 577, CHARACTER},
{CHARACTER, 0, 67, 578, CHARACTER},
{CHARACTER, 0, 76, 579, CHARACTER},
{CHARACTER, 0, 85, 580, CHARACTER},
{CHARACTER, 0, 68, 581, CHARACTER},
{CHARACTER, 0, 69, 582, CHARACTER},
{Q_MOC_INCLUDE_TOKEN, 0, 0, 0, CHARACTER},
{NEWLINE, 0, 0, 0, NOTOKEN},
{QUOTE, 0, 0, 0, NOTOKEN},
{SINGLEQUOTE, 0, 0, 0, NOTOKEN},
{WHITESPACE, 0, 0, 0, NOTOKEN},
{HASH, 0, 35, 581, HASH},
{HASH, 0, 35, 588, HASH},
{PP_HASHHASH, 0, 0, 0, NOTOKEN},
{BACKSLASH, 0, 0, 0, NOTOKEN},
{CPP_COMMENT, 0, 0, 0, NOTOKEN},

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2019 Olivier Goffart <ogoffart@woboq.com>
** Contact: https://www.qt.io/licensing/
**
@ -770,6 +770,12 @@ void Moc::parse()
case Q_OBJECT_TOKEN:
def.hasQObject = true;
break;
case Q_GADGET_EXPORT_TOKEN:
next(LPAREN);
while (test(IDENTIFIER))
{}
next(RPAREN);
Q_FALLTHROUGH();
case Q_GADGET_TOKEN:
def.hasQGadget = true;
break;
@ -847,6 +853,12 @@ void Moc::parse()
if (def.classname != "Qt" && def.classname != "QObject" && def.superclassList.isEmpty())
error("Class contains Q_OBJECT macro but does not inherit from QObject");
break;
case Q_GADGET_EXPORT_TOKEN:
next(LPAREN);
while (test(IDENTIFIER))
{}
next(RPAREN);
Q_FALLTHROUGH();
case Q_GADGET_TOKEN:
def.hasQGadget = true;
if (templateClass)

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
@ -154,6 +154,7 @@ QT_BEGIN_NAMESPACE
F(RETURN) \
F(Q_OBJECT_TOKEN) \
F(Q_GADGET_TOKEN) \
F(Q_GADGET_EXPORT_TOKEN) \
F(Q_NAMESPACE_TOKEN) \
F(Q_NAMESPACE_EXPORT_TOKEN) \
F(Q_PROPERTY_TOKEN) \

View File

@ -216,6 +216,7 @@ static const Keyword keywords[] = {
{ "Q_NAMESPACE", "Q_NAMESPACE_TOKEN" },
{ "Q_NAMESPACE_EXPORT", "Q_NAMESPACE_EXPORT_TOKEN" },
{ "Q_GADGET", "Q_GADGET_TOKEN" },
{ "Q_GADGET_EXPORT", "Q_GADGET_EXPORT_TOKEN" },
{ "Q_PROPERTY", "Q_PROPERTY_TOKEN" },
{ "Q_PLUGIN_METADATA", "Q_PLUGIN_METADATA_TOKEN" },
{ "Q_ENUMS", "Q_ENUMS_TOKEN" },

View File

@ -89,6 +89,8 @@ const char *string_hash_hash = STRING_HASH_HASH("baz");
Q_DECLARE_METATYPE(const QMetaObject*);
#define TESTEXPORTMACRO Q_DECL_EXPORT
namespace TestNonQNamespace {
struct TestGadget {
@ -140,6 +142,22 @@ namespace TestQNamespace {
Q_ENUM(TestGEnum2)
};
struct TestGadgetExport {
Q_GADGET_EXPORT(TESTEXPORTMACRO)
Q_CLASSINFO("key", "exported")
public:
enum class TestGeEnum1 {
Key1 = 20,
Key2
};
Q_ENUM(TestGeEnum1)
enum class TestGeEnum2 {
Key1 = 23,
Key2
};
Q_ENUM(TestGeEnum2)
};
enum class TestFlag1 {
None = 0,
Flag1 = 1,
@ -158,8 +176,6 @@ namespace TestQNamespace {
}
#define TESTEXPORTMACRO Q_DECL_EXPORT
namespace TestExportNamespace {
Q_NAMESPACE_EXPORT(TESTEXPORTMACRO)
enum class MyEnum {
@ -3954,6 +3970,12 @@ void tst_Moc::testQNamespace()
checkEnum(TestQNamespace::TestGadget::staticMetaObject.enumerator(1), "TestGEnum2",
{{"Key1", 23}, {"Key2", 24}});
QCOMPARE(TestQNamespace::TestGadgetExport::staticMetaObject.enumeratorCount(), 2);
checkEnum(TestQNamespace::TestGadgetExport::staticMetaObject.enumerator(0), "TestGeEnum1",
{{"Key1", 20}, {"Key2", 21}});
checkEnum(TestQNamespace::TestGadgetExport::staticMetaObject.enumerator(1), "TestGeEnum2",
{{"Key1", 23}, {"Key2", 24}});
QMetaEnum meta = QMetaEnum::fromType<TestQNamespace::TestEnum1>();
QVERIFY(meta.isValid());
QCOMPARE(meta.name(), "TestEnum1");