[Qt-interest] Q_CLASSINFO macro expansion
Colin S. Miller
no-spam-thank-you at csmiller.demon.co.uk
Sun Jan 24 15:58:44 CET 2010
Thomas Fjellstrom wrote:
> On Sun January 24 2010, Thiago Macieira wrote:
>> Em Sábado 23. Janeiro 2010, às 21.49.57, z escreveu:
>>> Hi all. Is there any way to make this work?
>>> <code>
>>> #define DBUS_INTERFACE "org.kde.test.dbserver"
>>> Q_CLASSINFO("D-Bus Interface", DBUS_INTERFACE)
>>> </code>
>> No.
>>
>
> You could probably run the pre processor on the file before you run moc on
> it, with most of QTs macros set to insert the text that was there (which
> should expand that macro, but not expand Q_CLASSINFO).
>
> But that would be horribly annoying, and error prone.
>
Actually, it isn't that error-prone.
One of my previous companies did it on their source for other reasons.
As long as you put
// MOC_SKIP_BEGIN
// MOC_SKIP_END
around all the #includes in your headers it should work fine.
This stops MOC from expanding QObject classes in other header files.
If this were to happen, then the linker will report errors when it
encounters several copies of the MOC generated functions.
If you are going down this route, I'd recommend using a different extension
for the QObject .h files (We used .mh for MOCable header). This
allows a build system to automatically invoke the preprocessor and MOC
on the header file.
HTH,
Colin S. Miller
More information about the Qt-interest-old
mailing list