How to override a superclass component signal handler

I have a base class element something like this:

Base .qml:

Item { Thing { id: theThing; onMySignal: { console.log("The signal"); } } } 

And I'm trying to make a derived element - Derived.qml .

How can I override the onMySignal theThing handler? I tried such things ...

Derived .qml:

 Base { theThing.onMySignal: { console.log("Do different things with theThing in Derived") } } 

but I cannot find anything to tell me how to express it syntactically correctly, or how and how to do it!

+5
source share
1 answer

You can define the signal handler code as a property in the superclass and override it in the derived element:

 Item { property var handlerCode: function () { console.log("In Superclass") }; Thing { id: theThing; onMySignal: handlerCode() } } 

Redefinition:

 Base { handlerCode: function () { console.log("In Derived Item!") }; } 
+4
source

Source: https://habr.com/ru/post/1211313/


All Articles