Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-125461

[enum] improve APIs for enum introspection

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • Core: Object Model
    • None

    Description

      Q_ENUM exposes a limited form of introspection to enums, including int/string conversions and element counts.

      it would be great to have some high-level functions (e.g. templated free functions) to access enums within a few single helper function rather than going through the `QMetaEnum` API, which is quite clunky

      MyEnum {
          Null,
      };
      
      MyEnum null{};
      QMetaEnum::fromType<MyEnum>()::valueToKey(null); // returns NULL
      

      there are some shortcuts, e.g. QTest::Internal::toString has an enum specialisation. but it would be great to have those functions in a publicly available place.

      my non-qt implementation for smart enums can possibly help as inspiration for a interface: https://github.com/timblechmann/nova_enums?tab=readme-ov-file#example

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            cnn Qt Core & Network
            timblechmann tim blechmann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes