[Interest] Qt namespaces and Q_MOC_RUN trick (aka: the mistery of qnamespace.h)

Sandro Andrade sandroandrade at kde.org
Thu Jan 10 19:26:14 CET 2013


On Thu, Jan 10, 2013 at 6:11 PM, Thiago Macieira
<thiago.macieira at intel.com> wrote:
> On quinta-feira, 10 de janeiro de 2013 17.21.31, Sandro Andrade wrote:
>> Hi there,
>>
>> I need to have some enums defined in a namespace like the ones we can
>> find at qtbase:src/corelib/global/qnamespace.h.
>>
>> I've tried the same approach in my project but moc complains with the
>> following: "Class contains Q_OBJECT macro but does not inherit from
>> QObject"
>>
>> I know we can use Q_GADGET instead of Q_OBJECT but I'm still getting
>> some build errors.
>>
>> The real point is: is there some 'magic' qmake flag or something else
>> used in qnamespace.h for having
>> that working properly ?
>
> Yes, there's magic hardcoded in moc and in QMetaObject::property.

:)

src/tools/moc/moc.cpp:

if (def.classname != "Qt" && def.classname != "QObject" &&
def.superclassList.isEmpty())
    error("Class contains Q_OBJECT macro but does not inherit from QObject");

Thanks,
Sandro

>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>



More information about the Interest mailing list