[Qt-interest] declare signals and slots in macros

Rush Manbert rush at manbert.com
Fri Mar 13 00:00:03 CET 2009


On Mar 12, 2009, at 3:32 PM, Andrea Franceschini wrote:

> Hi all,
> As you may have guessed, I am the one that always comes out with
> naughty code :) This time I tried to define a macro which dealt with
> the declaration of slots. Obviously macro expansion is not recursive,
> so basically when I put in my macro
>
> public slots:
>
> it is expanded as
>
> public :
>
> which makes a lot of things go wrong. So, as far as you know, is there
> a better way to achieve this? I so badly need to do that but of course
> the rules of the games are these. Ideas?
>

 From looking at include/Qt/qobjectdefs.h, it looks like you could get  
away with adding this to the header file where you define the macro

#ifdef Q_MOC_RUN
# define slots slots
#endif

because it looks like they define slots to expand to nothing, but only  
in the case where Q_MOC_RUN is not defined. But that seems pretty  
dangerous from a maintainability viewpoint. :-)

- Rush



More information about the Qt-interest-old mailing list