2

Is it possible to override an elements action (eg onTriggered() of a Timer) from within the onClick() of a button?

Something like so->

         Button {
                id: centerBtn
                objectName: "button"

                onClicked: {
                delaytimer.running = true;
                delayTimer.onTriggered {}; // override here

                }

                Timer {
                    id: delaytimer
                    interval: 1000
                    running: false
                    repeat: false
                    onTriggered: //something implemented here

                }
            }
2

You can define a property to store the code of the signal handler and reassign it when needed:

Look at the following snippet of code:

import QtQuick 2.0
import Ubuntu.Components 0.1

Rectangle {
    width: 200
    height: 150

    Button {
        id: foo
        text: "Foo"
        onClicked: {
            delaytimer.a = function () { console.log("Foo!") };
            delaytimer.running = true;
        }
    }

    Button {
        id: bar
        text: "Bar"
        anchors.left: foo.right
        onClicked: {
            delaytimer.a = function () { console.log("Bar!") };
            delaytimer.running = true;
        }
    }

    Timer {
        id: delaytimer
        interval: 1000
        running: false
        repeat: false
        property var a: function () { console.log("will be overridden!") };
        onTriggered: a()
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.