[Development] New Qt example development guideline and revamping examples
Kai.Koehne at qt.io
Wed Jan 18 17:10:20 CET 2023
> -----Original Message-----
> > MANDATORY
> > Do not use QT_BEGIN_NAMESPACE ... QT_END_NAMESPACE for example
> types. This namespace is exclusively for types in the Qt libraries.
> This is broken. How is one going to correctly forward declare Qt names
> in a namespaced build of Qt without using those macros?
Option 1: Do not forward declare the Qt type, but just include the right Qt header.
Option 2: Use QT_BEGIN_NAMESPACE..QT_END_NAMESPACE, but only for Qt types, _not_ for all header content.
The rule just says that wrapping all of your headers with QT_BEGIN_NAMESPACE, QT_END_NAMESPACE is a misfeature which shouldn't be cargo-culted.
> Is there perhaps
> a more comprehensive discussion regarding how to write examples that
> cope with namespaced Qt builds?
Personally, I wouldn't even mind if Qt examples wouldn't compile with a namespaced Qt (-qtnamespace configure argument), because I feel it's a somewhat specialist feature. But alas, we have at least one CI configuration that builds with -qtnamespace and Qt examples, so we might as well keep it working.
(A nasty feature of uic is btw that it also does generate C++ code inside QT_BEGIN_NAMESPACE, QT_END_NAMESPACE. That is, if you have a .ui file for a Dialog, and you want to pre-declare the type generated by uic, you have to also put it in QT_BEGIN_NAMESPACE, QT_END_NAMESPACE, which is a bit surprising to me . Anyhow, changing this is probably not worth the breakages anymore ...
More information about the Development