Welcome!

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

Reply
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

Change scope of created qml object

From my main qml i call another qml by using

 attachedObjects: [
    ComponentDefinition {
        id: splash
         source: "splash.qml"
     }
]

 I create the splash screen using

var splashSheet = splash.createObject();
splashSheet.open();

Now i want to change a label on this object.

I have exposed the label using a property alias.

As long as the variable is in scope i can use

splashSheet.stateLabel.text = "new text"

 How can i do this in another function where i cannot access the var splashSheet without creating a new object?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: Change scope of created qml object

You have to set its  alias property  for sample code you can refer below link in this megha explain how we can change the scope of qml object.

 

http://supportforums.blackberry.com/t5/Cascades-Development/Calling-an-element-id-from-one-QML-file-...

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Change scope of created qml object

i already did that, and it is working fine.

i want to do it from another function.
i create the splash object in
onCreationComplete, but want to access it in, say, myFunction().
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Change scope of created qml object

One option is just to define a variant property in your root component (or any other place that both pieces can access), and store a reference to the object there. That is, "property variant mySplash" and when you create it, keep a reference with "mySplash = splashSheet" and then later use "mySplash.stateLabel.text" to get to that.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Change scope of created qml object

that sounds like a good idea, i'll try it.

i got it working with attaching a Sheet instead of a ComponentDefinition, but your idea sounds better.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Change scope of created qml object

I get an error:
 Error: Invalid write to global property "splash"

i define the property like this:

property variant splash

 and have the component definition as an attached object:

attachedObjects: [
  ComponentDefinition {
  id: splashSheet
  source: "SplashSheet.qml"
}

 I try to create the screen like this:

splash = splashSheet.createObject()
splash.open()

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Change scope of created qml object

I'm doing basically the same but with a comp = Qt.createComponent("TestComponent.qml") call, followed by the equivalent of "splash = comp.createObject(thisPane)".

The error mentioning a "global property" suggests to me you're doing something wrong. Did you define it on the root component? It's not required to be there, but it should be safe there... Maybe you've got some other property already called "splash", maybe in some JavaScript?

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Highlighted
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Change scope of created qml object

I defined it in the Page, but after i moved it up to NavigationPane it worked.
The way of the code is sometimes mysterious.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter