Skip to content

Namespace incompatibilities

Ivailo Monev edited this page Jul 22, 2019 · 7 revisions

To properly supported namespaced toolkit build several changes have been made, including forward class declarations and macro use changes.

If toolkit class, e.g. QString, is forward declared in the default namespace instead of the toolkit namespace the compiler will not be able to reference it properly. For that reason script is provided with the project source code that can replace forward class declarations with headers inclusions. Do note that it cannot fix friend class forward declarations and friend operators for you so some manual adjustments may be needed. Alternatively, forward class declarations can be declared in the toolkit namespace via use of QT_BEGIN_NAMESPACE and QT_END_NAMESPACE macros.

Macros like Q_DECLARE_INTERFACE have to be used in the default namespace, not in the toolkit namespace (outside QT_BEGIN_NAMESPACE-QT_END_NAMESPACE scope).

Opposite of the macros changes, qHash and QDataStream overloads have to be in the toolkit namespace.

Last but not least, if QT_NAMESPACE_COMPAT is defined when building project that uses the toolkit all of the symbols the toolkits provides will be mangled into the default namespace which is the same as using namespace QT_NAMESPACE however if QT_NAMESPACE_COMPAT is used that will be done after the toolkit namespace has been forward declared which solves namespace references issues.