[Interest] how to add comments of member function defined with macro?
tang ke
tangk at lemote.com
Wed Feb 27 08:09:43 CET 2013
Thanks very much.
On 02/27/2013 02:58 PM, Carel Combrink wrote:
>
> 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
--
应用部 唐科
TEL : 0512-52308661-88686
FAX: 0512-52308688
MP : 18962393077
E-mail: tangk at lemote.com
地址:江苏省常熟市虞山镇梦兰工业园
More information about the Interest
mailing list