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

Improve documentation on how to register C++ types with enums for QML as value types and namespaces

    XMLWordPrintable

Details

    Description

      My understanding is that as of Qt 6.2 there is no need to manually register QML types, but that the macros will do that for us. Indeed that has been my experience, using several QML_ELEMENT and Q_GADGET classes.

      However enums only get recognised in QML for QML_ELEMENTs.

      I have attached a minimal example containing:

      1. A class derived from QObject, that has Q_OBJECT, QML_ELEMENT and Q_ENUM
      2. A class that has Q_GADGET and Q_ENUM
      3. A namespace that has Q_NAMESPACE and Q_ENUM_NS

      Of these three, only the first results in an enum that works in QML.

       

      I notice, looking at the resulting build folder, that mymodulelib_qmltyperegistrations.cpp only registers the module and the QObject; and that MyModuleLib.qmltypes only contains the enum of the Object.

      Attachments

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              paulmasri Paul
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes