Hi Guiseppe, thanks for the reply!
QT_TYPESAFE_FLAGS features prominently in the Qt documentation, see e.g https://doc.qt.io/qt-6/qflags.html#operator-and-eq What I found confusing is that operator!() is documented, but operator bool() is not. Also, the implicit conversion to int is not documented (at least I could not find it in the above page). There is "toInt()", but then I'd have to explicitly write if (flags.toInt()) // something I noticed that I can apparently static_cast flags to bool, but if I want to return a bool from a function, I have to use the explicit cast (which would be fine, if that is the way it's supposed to work). In summary, I find ways that seem to work, but the "correct" way is entirely unclear to me. Kind regards Robert > -----Original Message----- > From: Interest <[email protected]> On Behalf Of Giuseppe > D'Angelo via Interest > Sent: Wednesday, 18 February 2026 13:34 > To: [email protected] > Subject: Re: [Interest] QFlags: Typesafe way to check "any flag set" > > CAUTION: External Sender > Stop. Review. Verify! Were you expecting this mail? > If you were not expecting this email, confirm with the sender through a > trusted channel (e.g., phone or Teams). > If suspicious, please report the mail, do not click on any links or open > attachments, and do not enter any ID or password. > > > > 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.god/ > bolt.org%2Fz%2Fzebhah5cr&data=05%7C02%7Crobert.schimkowitsch%40and > ritz.com%7C8ec6793e6e2a4a2be89908de6eea4643%7C6785298fe857464b9b > 4b807178402632%7C1%7C0%7C639070149677209429%7CUnknown%7CTWF > pbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4 > zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=uZaT1mf > 4ToLAUG1y4zQnS737O439QnGkpanFjOqnI94%3D&reserved=0 > > 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.kd/ > ab.com%2F&data=05%7C02%7Crobert.schimkowitsch%40andritz.com%7C8ec > 6793e6e2a4a2be89908de6eea4643%7C6785298fe857464b9b4b80717840263 > 2%7C1%7C0%7C639070149677252552%7CUnknown%7CTWFpbGZsb3d8eyJF > bXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiT > WFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=pr9CsJABgekUEYIcuIo7 > nemGqjp8Et2PgY2qG8bRkUw%3D&reserved=0 > KDAB - Trusted Software Excellence ________________________________ This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system. ANDRITZ HYDRO GmbH Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation Firmensitz/ Registered seat: Wien Firmenbuchgericht/ Court of registry: Handelsgericht Wien Firmenbuchnummer/ Company registration: FN 61833 g DVR: 0605077 UID-Nr.: ATU14756806 Thank You ________________________________ _______________________________________________ Interest mailing list [email protected] https://lists.qt-project.org/listinfo/interest
