Run javascript function when a page loaded in QML

2 8 picture 2 8 · Mar 29, 2013 · Viewed 15.6k times · Source

I want to run js function like this

function setPersonalInfoValue(){
        console.debug("setPersonalInfoValue()");
    }

when the page loaded in QML.

I tried this:

Rectangle {
    id: page2
    width: 100
    height: 62

    function setPersonalInfoValue(){
        console.debug("setPersonalInfoValue()");
    }
}

I want to run setPersonalInfoValue() function when I switch between page 1 to page 2. How can I do this?

Answer

2 8 picture 2 8 · Mar 29, 2013

Finally, I used:

Component.onCompleted: {
    setPersonalInfoValue();
}