Do not unconditionally define QT_BEGIN_MOC_NAMESPACE
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>
Fri, 30 Dec 2011 13:18:28 +0000 (14:18 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Jan 2012 12:33:11 +0000 (13:33 +0100)
Qt5 modules are supposed to be in a namespace, but if the namespace definition
is hidden in a macro, then moc doesn't know about it and generates invalid
moc_xx.cpp that cannot be compiled due to usage of classes outside of their
namespaces - e.g. in qtjsondb we have QtAddOn::JsonDb::Foo class, but the
moc_foo.cpp expects to find that class in the global namespace instead.

Fixed it in QtJsonDb to define QT_BEGIN_MOC_NAMESPACE="QT_USE_NAMESPACE
QT_ADDON_JSONDB_USE_NAMESPACE", however we need to ensure qglobal.h doesn't
re-define that macro back.

Change-Id: Ic8407f50c11d2d787167ad2f92457aa3ec126d45
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Richard J. Moore <rich@kde.org>
Reviewed-by: Toby Tomkins <toby.tomkins@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
src/corelib/global/qglobal.h

index e75118f..785ee4a 100644 (file)
 # define QT_END_NAMESPACE
 # define QT_BEGIN_INCLUDE_NAMESPACE
 # define QT_END_INCLUDE_NAMESPACE
+#ifndef QT_BEGIN_MOC_NAMESPACE
 # define QT_BEGIN_MOC_NAMESPACE
+#endif
+#ifndef QT_END_MOC_NAMESPACE
 # define QT_END_MOC_NAMESPACE
+#endif
 # define QT_FORWARD_DECLARE_CLASS(name) class name;
 # define QT_FORWARD_DECLARE_STRUCT(name) struct name;
 # define QT_MANGLE_NAMESPACE(name) name
 # define QT_END_NAMESPACE }
 # define QT_BEGIN_INCLUDE_NAMESPACE }
 # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
+#ifndef QT_BEGIN_MOC_NAMESPACE
 # define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
+#endif
+#ifndef QT_END_MOC_NAMESPACE
 # define QT_END_MOC_NAMESPACE
+#endif
 # define QT_FORWARD_DECLARE_CLASS(name) \
     QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
     using QT_PREPEND_NAMESPACE(name);