Call a function by onClicked in qml



  • I am trying to call a function clearcanvas by "onClicked" event of the button.
    Can anybody help me out on this so that when I click on the button it should call the function and execute it.

    !http://instacod.es/file/75943(My code look like)!



  • 1 : Declare the function clear outside of the Canvas component
    2 : Declare the var ctx as a property of canvas
    3: please post your codes by text rather than image next time, this would easier for us to help you

    @
    QtObject{
    id: param

    function clearCanvas(ctx){
    ctx.clearRect(....)
    }
    }

    Canvas{
    id:canvas

    property var ctx
    

    }

    //.....
    Rectangle{
    //.....
    MouseArea:{
    anchors.fill:parent

    onClicked:{
    clearCanvas(canvas.ctx)
    }
    }
    }
    @



  • Thank you for suggestion.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.