On 18/02/2026 13:00, Schimkowitsch Robert wrote:
When I look at qflags.h in 6.10.2, I notice that there is

constexpr inline bool operator!() const noexcept { return !i; }

…but operator bool() is listed in the non-TYPESAFE section.

Does this mean that if I want to check if any flag is set, I need to do this?

// Check if any flag is set

if ( !! flags)

{ /* do something */ }


Are you looking at

#ifdef QT_TYPESAFE_FLAGS
    constexpr inline explicit operator Int() const noexcept { return i; }
    constexpr inline explicit operator bool() const noexcept { return i; }
#else
    constexpr inline Q_IMPLICIT operator Int() const noexcept { return i; }
    constexpr inline bool operator!() const noexcept { return !i; }
#endif

?

In the else branch (non-typesafe) there's an implicit operator int(), so you can just write if (flags) or if (flags != 0). https://gcc.godbolt.org/z/zebhah5cr

Note that QT_TYPESAFE_FLAGS is a Qt-internal feature at the moment, and not enabled for user code. (Qt itself isn't clean, only QtCore builds with it.)

HTH,
--
Giuseppe D'Angelo | [email protected] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - Trusted Software Excellence

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest

Reply via email to