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

QML_FOREIGN_NAMESPACE not working for namespace located outside of binary

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • 6.7
    • 6.6.2, 6.7.0
    • QML: Tooling
    • None
    • Linux/X11

    Description

      I have a first library that defines a namespace like:

      namespace WarningState
      {
      Q_NAMESPACE_EXPORT(HELPLIB_EXPORT)
      enum class State
      {
          Unknown,
          Information,
          Warning,
          Error,
          Success
      };
      Q_ENUM_NS(State);
      }  // namespace WarningState

      Then In a QML reusable module, I want to register it to be able to use the enum in QML code.

      For that I added this to my module:

      namespace WarningStateForeign
      {
      Q_NAMESPACE
      QML_NAMED_ELEMENT(WarningState)
      QML_FOREIGN_NAMESPACE(WarningState)
      };

      The code generated does not build. 
      Here is the generated code:

      Q_QMLTYPE_EXPORT void qml_register_types_Help()
      {
          qmlRegisterTypesAndRevisions<HelpNotificationListModelForeign>("Help", 1);
          QMetaType::fromType<WarningState>().id();
          qmlRegisterNamespaceAndRevisions(&WarningState::staticMetaObject, "Help", 1, nullptr, &WarningStateForeign::staticMetaObject, nullptr);
          qmlRegisterModule("Help", 1, 0);
      }

      The error is on line

      QMetaType::fromType<WarningState>().id();

      WarningState is an enum. If I remove this line of code it works correctly and everything is correctly registered to QML. 
      If I move the namespace definition in the QML module (instead of beeing in a separated library) it also works.

      Attachments

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

        Activity

          People

            fabiankosmale Fabian Kosmale
            loiczimm Loic Zimmermann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes