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

qmlsc: Object type * is not derived from QObject or QQmlComponent when using templates

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 6.4.0 Beta1
    • QML: Compiler, QML: Tooling
    • None
    • Windows

    Description

      When using an object derived from a template

      template<class T>
      class TemplateTest : public QObject
      {
      public:
          using QObject::QObject;
      };
      
      class SubTestObject : public TemplateTest<QObject>
      {
          Q_OBJECT
          QML_ELEMENT
      public:
          using TemplateTest<QObject>::TemplateTest;
      };
      
      class TestObject : public QObject
      {
          Q_OBJECT
          QML_ELEMENT
          Q_PROPERTY(SubTestObject* value READ get_value CONSTANT FINAL)
      public:
          explicit TestObject(QObject *parent = nullptr);
      
      public Q_SLOTS:
          SubTestObject* get_value() const {
              return new SubTestObject();
          }
      };
      

      then this error is shown:

      error: Object type SubTestObject is not derived from QObject or QQmlComponent
      

      When using a non-template parent then no error is shown:

      class SubTestObject : public QObject
      {
          Q_OBJECT
          QML_ELEMENT
      public:
          using TemplateTest<QObject>::TemplateTest;
      };
      

      The error also happens if the templated parent is not the direct parent, for instance:

      class SubTestObject2 : public SubTestObject
      {
          Q_OBJECT
          QML_ELEMENT
      public:
      };
      
      // and use SubTestObject2 as property.
      

      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
            Harald Meyer Harald Meyer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes