C++ Inheritance and QML component reuse



  • Hi,
    I have C++ class that is registered to QML:

    // baseclass.cpp
    BaseClass {
       virtual void doSomething();
    }
    
    qmlRegisterType<BaseClass >("Repository", 1, 0, "BaseClassItem");
    

    and QML component that graphically represents that type:

    // base.qml
    BaseClassItem {
     id: base
    // some graphics
    // and some functionality, e.g. on click do something
    MouseArea{
            anchors.fill: parent
            onClicked: {
                base.doSomething();
            }
        }
    }
    

    What is the correct way to implement new QML component that reuses base.qml and inherits functionatity from BaseClass? Derived QML component should reuse graphics from base.qml and provide some additional content to it (e.g. draw a rectangle in the center of base.qml)

    // derivedclass.cpp
    DerivedClass : public BaseClass {
     void DoSomething();
    }
    
    qmlRegisterType<DerivedClass >("Repository", 1, 0, "DerivedClassItem");
    
    // derived.qml
    ???
    

  • Moderators


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.