I have two enums. They are in the same namespace, but different header files. To make them available to Qt meta type system, I try this:
- With the above I get duplicate symbol linker error. Because both moc_C1.o and moc_C2.o defined the staticMetaObject that result from Q_NAMESPACE
- Both headers must contain Q_NAMESPACE. Otherwise moc complains "Error: Namespace declaration lacks Q_NAMESPACE macro."
- If I have only one of C1.h or C2.h, it works.
- If I move content of C2.h into C1.h, it also works
The core of the problem seems to be that with multiple header files, the toolchain doesn't know how to define only one copy of the namespace's meta object stuff.
The following looks like a reasonable effort:
With the above:
- moc_SW_MetaDef.cpp defines the only copy of SW namespace's meta object stuff
- The staticMetaObject referenced by Q_ENUM_NS is visible. So should be no compiler error there
- But moc would output "Error: Namespace declaration lacks Q_NAMESPACE macro." Is moc being too strict? Would the above work if we disable the "Q_NAMESPACE present" check in moc?