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

QML_FOREIGN_NAMESPACE unable to find classes that have been aliased

    XMLWordPrintable

Details

    • All

    Description

      QML_FOREIGN_NAMESPACE is unable to find classes referenced via an alias, producing warning: com::AliasName is declared as foreign type, but cannot be found.

      Alias creation can be done with either the "using" syntax or the "typedef" syntax. Both will result in the same warning.

      The following example can be copy-pasted into a header to re-produce the issue:

      #ifndef CLASSNAME_H
      #define CLASSNAME_H
      #include <QObject>
      #include <QQuickItem>

      namespace com {

      namespace A {
      class ClassName
      {
      Q_GADGET
      QML_ELEMENT
      };
      } // namespace A

      // Class B comes from namespace A
      using AliasName = com::A::ClassName;
      //// Alternatively we could use typedef and it would produce the same outcome
      // typedef com::A::ClassName }}{{{}AliasName;

      namespace B {
      Q_NAMESPACE
      QML_FOREIGN_NAMESPACE(com::AliasName)
      QML_NAMED_ELEMENT(ClassName)
      } // namespace B
      } // namespace com

      #endif // CLASSNAME_H

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            javier.cordero Javier Cordero
            Votes:
            6 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes