From 620f911fd8456351019bcc116f740501d88a0537 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 29 Mar 2013 18:08:15 -0700 Subject: [PATCH] Update the QMetaMethod::tag() documentation due to moc expanding macros Since 34a3b63dc7d3b09342647537d378f5a55d0c81f0 (Qt 5.0), moc expands macros to their defined values. This broke the example of tagging a method: in Qt 4, it never expanded anything, so the tag was always visible and extracted. Now it's necessary to avoid defining it to empty when moc is run. Change-Id: I89967f7f993cf8e14119b086f4dd5573b348646d Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetaobject.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index b581be821b..00d20d9300 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1854,7 +1854,10 @@ const char *QMetaMethod::typeName() const way in the function declaration: \code - #define THISISTESTTAG // tag text + #ifndef Q_MOC_RUN + // define the tag text + # define THISISTESTTAG + #endif ... private slots: THISISTESTTAG void testFunc(); @@ -1871,8 +1874,13 @@ const char *QMetaMethod::typeName() const qDebug() << mm.tag(); // prints THISISTESTTAG \endcode - For the moment, - \c moc doesn't support any special tags. + For the moment, \c moc will extract and record all tags, but it will not + handle any of them specially. + + \note Since Qt 5.0, \c moc expands preprocessor macros, so it is necessary + to surround the definition with \c #ifndef \c Q_MOC_RUN, as shown in the + example above. This was not required in Qt 4. The code as shown above works + with Qt 4 too. */ const char *QMetaMethod::tag() const {