[Development] How to have equivalent of function over-riding in Qml
travik
ravikiran.tallapalli at wipro.com
Thu Jul 10 05:41:08 CEST 2014
>
> Thanks for the very quick reply.
> Thank you for clarifying my understanding of correct derivation in Qml
>
> Regards,
> R.kiran
>
Hi In continuation of the previous post - I now got it working to invoke
the base class / derived class implementations correctly from extenal
place.
Now the question is: Can I have my derived class, call the base class
implementation as part of its functionality?
C++ equivalent would be something like this:
class Base
{
public:
void method1()
{
std::cout << "Base::method1().." << std::endl;
}
};
class Derived: public Base
{
public:
void method1()
{
std::cout << "Derived::method1()..pre.." << std::endl;
// Derived class uses the base class implementation fully
// and does something extra on its own.. true case of extending the
// functionality, if I may say so!
Base::method1();
std::cout << "Derived::method1()..post.." << std::endl;
}
};
Qml Equivalent would be (to the extent I have figured out)
Base.qml
----
Item
{
function method1()
{
console.log("Base::method1()...")
}
}
Derived.qml (in the same folder as Base.qml)
---
Base
{
function method1()
{
console.log("Derived::method1()...")
}
}
I tried this, it ended up in recursive loop, obviously!!
Derived.qml
---
Base
{
id: myBase
function method1()
{
console.log("Derived::method1()...pre")
// myBase.method1() // <<--- calls the same method recursively
// Base.method1() // <<--- this line gives undefined object,
naturally!
console.log("Derived::method1()...post")
}
}
More information about the Development
mailing list