Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run javascript function when a page loaded in QML

Tags:

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?

like image 890
Vahid Kharazi Avatar asked Mar 29 '13 08:03

Vahid Kharazi


People also ask

How call JavaScript function in QML?

You need to load a TabContainers instance in your current QML and call the function tabClicked() on it for it to work. If your TabContainers instance is loaded in another QML file of your application you could also define a signal in one of their common ancestor and emit the signal in X.

Does QML support JavaScript?

JavaScript ExpressionsQML has a deep JavaScript integration, and allows signal handlers and methods to be defined in JavaScript. Another core feature of QML is the ability to specify and enforce relationships between object properties using property bindings, which are also defined using JavaScript.

How do you define a function in QML?

Define the function in your root-node ( ApplicationWindow ). This will be the last place, QML will look for a name, before it resorts to the C++ -context properties. See here to find out, how the names of variables and functions are resolved in QML.


1 Answers

Finally, I used:

Component.onCompleted: {     setPersonalInfoValue(); } 
like image 108
Vahid Kharazi Avatar answered Oct 13 '22 04:10

Vahid Kharazi