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. C++ Inheritance and QML component reuse

C++ Inheritance and QML component reuse

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 827 Views
  • 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.
  • M Offline
    M Offline
    MartinD
    wrote on 27 May 2016, 14:01 last edited by MartinD
    #1

    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
    ???
    
    P 1 Reply Last reply 27 May 2016, 16:32
    0
    • M MartinD
      27 May 2016, 14:01

      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
      ???
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 27 May 2016, 16:32 last edited by
      #2

      Hi @MartinD,
      Something like this:
      https://forum.qt.io/topic/56491/has-a-relationship-in-qml/3

      157

      1 Reply Last reply
      0

      1/2

      27 May 2016, 14:01

      • Login

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