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

qmltyperegistrar cannot see the base class of a QML_ELEMENT from a different module

    XMLWordPrintable

Details

    • c45c32af3 (dev), bc2ae5a70 (dev), 7d01e7ef8 (dev)

    Description

      Code

      // cppbase.h, in submodule
      #include <QQmlEngine>
      
      class CppBase : public QObject
      {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          explicit CppBase(QObject* parent = nullptr) : QObject(parent) {}
      };
      
      // cppderived.h, in "main" module
      #include "MyModule/cppbase.h"
      
      class CppDerived : public CppBase
      {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          explicit CppDerived(QObject* parent = nullptr) : CppBase(parent) {}
      };
      

       

      Compiler output

      Warning: Main.qml: Object type CppDerived is not derived from QObject or QQmlComponent. You may need to fully qualify all names in C++ so that moc can see them. You may also need to add qt_extract_metatypes(<target containing >). [compiler]
      

       

      Workaround

      Instead of linking to the plugin target, link directly to the backing target. In other words, replace this...

      target_link_libraries(appCrossModuleDerivation
          PRIVATE Qt6::Quick MyModuleplugin
      )
      

      ...with this:

      target_link_libraries(appCrossModuleDerivation
          PRIVATE Qt6::Quick MyModule
      )
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-115152
          # Subject Branch Project Status CR V

          Activity

            People

              alexandru.croitor Alexandru Croitor
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews