Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Error while qmlRegisterType with multiple inheritance class
Qt 6.11 is out! See what's new in the release blog

Error while qmlRegisterType with multiple inheritance class

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 678 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yujeonja
    wrote on last edited by
    #1

    I have a class called View which inherits from QQuickItem.
    And now I create class Box which inherits QQuickPaintedItem and View.

    class Box : public QQuickPaintedItem, public View
    {
        // Q_OBJECT  <- this also make errors so I removed it.
        ....
    }
    

    The problem is when I register this class with qmlRegisterType, there are some errors.

    qmlRegisterType<Box>(uri, 0, 1, "Box");
    

    First is

    /usr/include/qt/QtQml/qqmlprivate.h:71:49: error: reference to ‘Box::staticMetaObject’ is ambiguous
       71 |     const char *className = T::staticMetaObject.className(); \
          |                                ~~~~~~~~~~~~~~~~~^~~~~~~~~
    
    

    And second is

    /usr/include/qt/QtCore/qmetatype.h:1529:40: error: ‘QObject’ is an ambiguous base of ‘Box’
     1529 |         enum { Value = sizeof(checkType(static_cast<T*>(nullptr))) == sizeof(yes_type) };
          |                              ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    And last one

    /usr/include/qt/QtQml/qqml.h:349:51: error: reference to ‘Box::staticMetaObject’ is ambiguous
      349 |         uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
          |                                                   ^~~~~~~~~~~~~~~~~~~~
    

    Is it impossible to register QML C++ extension that multiple inheritance class?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      @Yujeonja said in Error while qmlRegisterType with multiple inheritance class:

      class Box : public QQuickPaintedItem, public View

      Any chances that View also inherits QObject like QQuickPaintedItem ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Yujeonja
        wrote on last edited by
        #3

        @SGaist
        Of course it's possible(View is also my code). But my concern is whether there will be any performance issues.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can't have double inheritance from QObject based class. That is the current issue you are hitting.

          Does you view class really need to be QObject based ?
          Do you really need to inherit from it rather than use it (i.e. composition) ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yujeonja
            wrote on last edited by
            #5

            I discard QQuickPaintedItem and using updatePaintNode with QImage and QSGTexture.
            The idea from https://stackoverflow.com/a/58597344/5902108

            Below is my code.

            QSGNode* Box::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
            {
                QImage canvas(View::width(), View::height(), QImage::Format_ARGB32);
                QBrush brush;
            
                canvas.fill(QColor("transparent"));
            
                QPainter painter(&canvas);
                brush.setStyle(Qt::SolidPattern);
                brush.setColor(this->color());
                painter.setPen(Qt::NoPen);
                painter.setBrush(brush);
                painter.drawRect(0, 0, View::width(), View::height());
            
                QSGTexture *texture = this->window()->createTextureFromImage(canvas);
                QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode*>(oldNode);
                if (!node) {
                    node = new QSGSimpleTextureNode();
                }
                node->setRect(0, 0, View::width(), View::height());
                node->setTexture(texture);
            
                return node;
            }
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved