简体   繁体   中英

Run javascript function when a page loaded in QML

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?

Finally, I used:

Component.onCompleted: {
    setPersonalInfoValue();
}

The answer to this question depends on how exactly you are switching pages. If you are dynamically loading the pages then you can use Component.onCompleted. This will execute when QML has finished loading the object. If you are using some other method such as changing the visibility to show a different page then you should rely on the onChanged signal for that property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM