On 04.05.23 15:51, Sune Vuorela wrote: > On 2023-05-04, Marc Mutz via Development <development@qt-project.org> wrote: >> that keeps unported code running. The main issue isn't the scoping, the >> main issue will be the missing implicit conversion to underlying_type. > > In few cases the implicit conversion to underlying_type is kind of important. > > Especially in the cases where the api has int and is mostly used with > enums or is somehow user extendable. > > Qt::ItemDataRole is one of them that comes to mind. > > switch(role) { > case Qt::UserRole+1: > .... > > QEvent::Type is another one where one registerEventType, recieves an int > and then force-cast it to QEvent::Type and still compares back to that > int in other places.
The int is the problem, not the enum. With C++17, scoped enums have a kind of explicit ctor from underlying_type, so at least that direction is reasonably convenient. For the other direction, there's std::to_underlying/qToUndelying(). So, enum-backed APIs taking int will have to be ported to take the enum instead. On the plus side, you get type-richer and safer APIs. Thanks, Marc -- Marc Mutz <marc.m...@qt.io> Principal Software Engineer The Qt Company Erich-Thilo-Str. 10 12489 Berlin, Germany www.qt.io Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B -- Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development