[Development] better compile-time os detection

Edward Welbourne edward.welbourne at qt.io
Tue Jul 21 11:20:30 CEST 2026


Tim Blechmann (21 July 2026 06:45) suggested (inter alia):
> B: map OS defines to constexpr bool variables
> qt's preprocessor defines can only be used on the preprocessor, but we
> could map all Q_OS_XXX defines. easily done, we'd get something like:
> ```
> namespace Qt::Cfg::Os {
> inline constexpr bool isLinux = true;
> inline constexpr bool isAndroid = true;
> }
> ```
> would also work for other preprocessor defines

Has the virtue of straightforwardness.

> C: separate "OS" from "Platform"
> one could treat Android or OHOS as "platform" rather than "operating
> system". this is how boost.predef handles android for example:
> https://www.boost.org/doc/libs/latest/libs/predef/doc/#_using_the_predefs

Sounds well structured and could, of course, be combined with B.

> D: separate "OS" from "OS family"
> if we introduce a concept of "OS family", one could group, e.g. linux,
> android, ohos as one "linux family", like one could treat
> ios/ipados/visionos/tvos/watchos as "ios family"

For reference, the "ios family" is called Darwin and we already have a
define for that.  So this has a precedent.

	Eddy.


More information about the Development mailing list