Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.10.1
-
None
Description
Funny thing that Q_NAMESPACE is not documented at all. It's lame.
The simpliest solution is to create header file for macro and include it from every and each isolated header.
h_0.h
#pragma once namespace E { Q_NAMESPACE }
It's not a bug, but definitely should be documented in docs.
UPDATE1:
It's a piece of bug, lol. Or, at least, very poor design which ruins the idea. It won't compile this easy. MOC generates error.
Here's setup of tests. Folowing table shows where do we use Q_NAMESPACE macro
Setup | h_0.h | h_i.h |
---|---|---|
1 | - | - |
2 | here | - |
3 | - | here |
4 | here | here |
And that's what I got (gcc, msvc2015):
setup_1:
'staticMetaObject' was not declared in this scope inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; }
\QTBUG-68611\h_0.h:-1: No relevant classes found. No output generated. \QTBUG-68611\h_1.h:6: error: Namespace declaration lacks Q_NAMESPACE macro. \QTBUG-68611\h_2.h:6: error: Namespace declaration lacks Q_NAMESPACE macro. \QTBUG-68611\h_1.h:13: error: C2065: 'staticMetaObject': undeclared identifier \QTBUG-68611\h_2.h:13: error: C2065: 'staticMetaObject': undeclared identifier
setup_2
moc reports
..\QTBUG-68611\h_2.h(6): Error: Namespace declaration lacks Q_NAMESPACE macro.
setup_3 and setup_4
\QTBUG-68611\h_0.h:-1: Note: No relevant classes found. No output generated. moc_h_2.cpp:-1: error: multiple definition of `E::staticMetaObject'
moc_h_2.obj:-1: error: LNK2005: "struct QMetaObject const E::staticMetaObject" (?staticMetaObject@E@@3UQMetaObject@@B) already defined in moc_h_1.obj
debug\QTBUG-68611.exe:-1: error: LNK1169: one or more multiply defined symbols found