[Interest] how to add comments of member function defined with macro?

Carel Combrink carel.combrink at gmail.com
Wed Feb 27 07:58:20 CET 2013


> My defined macro such as Q_OBJECT, the macro will define the common
> member function.
>
>
I have the same function, but instead of a macro I make use of templates.
This can be done since the  metaObject can be obtained from the
staticMetaObject on the class. Using templates you get the same behaviour
but you do not need to create the function for each class, but you make use
of templates to do it for you only when you need to call the function.

        template <class object>

        QString enumToString(const char* enumName, int enumValue) {

            QString enumString;

            const QMetaObject metaObject = object::staticMetaObject;

            int enumIndex = metaObject.indexOfEnumerator(enumName);

            if(enumIndex == -1) {

                /* The enum does not contain the specified enum */

                Q_ASSERT(enumIndex != -1);

                return enumString;

            }

            QMetaEnum en = metaObject.enumerator(enumIndex);

            enumString = en.valueToKey(enumValue);

            return enumString;

        }

        //--------------------------------------------------


The implementation is a bit different but the idea is the same. Perhaps you
can use something similar to create a 'global' template function that works
on all QObjects that defines Q_ENUMS and then just comment on that function.

Regards,
Carel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130227/713d3532/attachment.html>


More information about the Interest mailing list