[Development] On ensuring that private headers include at least one other

Volker Hilsheimer volker.hilsheimer at qt.io
Tue Jun 24 10:58:19 CEST 2025


> On 24 Jun 2025, at 07:56, Sze Howe Koh <szehowe.koh at gmail.com> wrote:
> 
> A few years ago, our private headers were updated to include
> qglobal_p.h. Examples:
> * https://codereview.qt-project.org/c/qt/qtbase/+/121135
> * https://codereview.qt-project.org/c/qt/qtdeclarative/+/395249
> 
> The commit messages say, "See script in qtbase/util/includeprivate for
> the rules", but I wasn't able to find this script.
> 
> 1. What's the rationale for #include-ing private headers like this?
> 2. Is a copy of the script published somewhere? Should the script be
> pushed to qtbase/util/includeprivate as advertised?
> 3. Should the rules be enshrined in a QUIP, and/or should the Sanity
> Bot be given a new job?
> 

On the rationale:

The first change adds the include of QtCore/private/qglobal_p.h to qlogging_p.h. So the code is now:

#include <QtCore/private/qglobal_p.h>

QT_BEGIN_NAMESPACE

…


Without the qglobal_p.h include, QT_BEGIN_NAMESPACE would be undefined if a translation unit includes qlogging_p.h first.


I have no knowledge about the script, but sanity bot checking that there is an include before any `QT_` or `Q_` preprocessor symbol is used would be useful, for any header (it would have saved me a bit of head scratching recently, leading to https://codereview.qt-project.org/c/qt/qtbase/+/654258).

Volker



More information about the Development mailing list