Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override signal handler of superclass component

I have a base class item something like this:

Base.qml:

Item {
    Thing {
      id: theThing;

      onMySignal: { console.log("The signal"); }   
     }
}

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

How can I override the onMySignal handler of theThing? I have tried stuff like this...

Derived.qml:

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

but I can't find anything to tell me how to express this syntactically correctly, or whether/how to actually go about it!

like image 690
GreenAsJade Avatar asked Jan 17 '15 06:01

GreenAsJade


1 Answers

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

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

    Thing {
      id: theThing;

      onMySignal: handlerCode() 
     }
}

Overriding :

Base {
    handlerCode: function () { console.log("In Derived Item!") };
}
like image 199
Nejat Avatar answered Oct 23 '22 18:10

Nejat