Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Call a JS function from another QML

I have 2 QMLs, the 1st one has the JS Function, I want to call the JS Function in the 2nd QML.

I believe this can be done but can't find any resources how to do this. Any suggestions please?

Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Call a JS function from another QML

[ Edited ]

if your js function is not in main .qml this method should help out (if it is, move it to 2nd qml)

//reasoning for moving is the only way i have found to access something from main qml in another is to use qsettings, but that doesn't quite work out for functions.


1st qml (with function)

Container {
   id: root
   property alias thisRoot: root

   function myFunction(){
       //do stuff

main.qml (or 2nd qml)

Button {
  onClicked: {
Posts: 426
Registered: ‎04-10-2011
My Device: Z30

Re: Call a JS function from another QML

It depends on the relationship of the QML files as well as what the function achieves.
If the function is just some computation function that is independent of the QML component it is declared in, you can extract it to a .js file.
If the 2nd QML is included in the 1st on (so a custom component display), then you can just call the function similar to what slashkyle proposed.
Check out my apps in the BlackBerry World
Visit my developer blog alopix.net
BBM Channel: C0047B612