[Development] better compile-time os detection
Volker Hilsheimer
volker.hilsheimer at qt.io
Wed Jul 22 10:22:29 CEST 2026
> On 21 Jul 2026, at 06:45, EXT Tim Blechmann via Development <development at qt-project.org> wrote:
>
> working on some way of OS detection without preprocessor, there are a
> few shortcomings of QOperatingSystemVersion::OSType: most notably, it's
> impossible to dispatch linux-specific code, as there is no OSType::Linux
> (by design, as Android/OHOS are linux based as well). thiago recommended
> to discuss this on the list.
>
> some options:
[…]
>
> ----
>
> thoughts?
It would help to understand better for what kind of “linux-specific code” you would use such a QOSV.
Is it code using some posix APIs (which would likely also exist, but perhaps not be the best choice, on Android)? Is it code using some subsystem API that only exists on linux (but then perhaps not on every linux system)?
Looking at current usage of Q_OS_LINUX, they are mostly combined with some other condition. The comparatively rare “naked” usages of Q_OS_LINUX are either in code that is only compiled on Unix-ish systems (such as QPA code, which might be used on some RTOS platforms as well), or would also work on e.g. Android.
Perhaps QSysInfo already provides you with the information you are conceptually looking for; its QString-based API doesn’t allow for any compile-time checking though.
Volker
More information about the Development
mailing list