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
shreyansjain
Posts: 146
Registered: ‎07-03-2013
My Device: BB 9360
Accepted Solution

Right place to Initialize the findChild by object Name

Hi, 
So, I am using some data from the network and parsing it and then signaling the page in the navigation pane to update  the label in that page. 

So, I am using signal in QML and from QT, i am signalling the navigation pane to update the labels. 

So, now after I am done parsing, i signal the QML (it works as it prints the debug string), but if i got back to the navigation pane again and click refresh, it doesn't update the labels even though i use 

	Label* name = dashPage->findChild<Label*>("nameLabelObject");
	name->setText(" Test Value ");
	name->text();

 it returns "Test Value", but on the page it doesn't update with the new value. 

 

I know it could be somewhere wrong where I am initializing to find the child by object name. 

Currently, I am initalizing when i click a "refresh" button.

onTriggered{
     _app.refreshLabels();
}

and the following is the snippet from refreshLabels()

name = dashPage->findChild<Label*>("nameLabelObject");
	name->setText(" Test Value ");

 

So, my question is:

where is the best place to initialize 

name = dashPage->findChild<Label*>("nameLabelObject");

It gets created everytime I call _app.refreshLabels(). So, do i want it there or when I initialize my app (the constructor).

 

Thanks! 

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: Right place to Initialize the findChild by object Name

The best place to put it is.. nowhere at all, and to pass an object into Cacades that you use to set the property of the label in QML :smileyhappy:

 

This keeps the UI and application logic more separate.

 

That said, if you want to use findChild you should try and avoid calling it to often (do it once and keep a reference to the Label), since it's a bit expensive. I'm not sure why that's not working for you, it looks reasonable, and you say are getting what you expect from text(). If findChild fails you get a null pointer, or maybe an object you didn't mean to ask for.

 

More sample code might help

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Right place to Initialize the findChild by object Name


PBernhardt wrote:
.....

 

That said, if you want to use findChild you should try and avoid calling it to often (do it once and keep a reference to the Label), since it's a bit expensive.....


hmmm ..... if going the dynamic way and create / destroy pages always - a result is that you have to use findChild again instead of holding a reference

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
shreyansjain
Posts: 146
Registered: ‎07-03-2013
My Device: BB 9360

Re: Right place to Initialize the findChild by object Name

Thanks Paul,

So, I got it working in the following way:

1) A list Item is clicked, it invokes a function in Qt to connect the signal A with another signal B (defined within QML)

2) Once the parsing is done, it emits the signal A and subsequently calls signal B in QML

3) Now in the onSignalB in QML, i just use alias property to change the label text in ComponentDefinition source page and push that page to the navigationPane.  

4) Once you pop out of the navigationPane, it invokes another function in Qt, to delete that particular object.

obj->deleteLater();

This way I am deleting the object once we dont need it.

The new object is created again when the listItem is clicked and 1) - 4) is run again.

 

Does it sound reasonable? It works but need to ensure it doesn't have too much cost associated with it.

 

also, when you  say "findChild you should try ..  it's a bit expensive. ", how do you define expensive here? 

 

Thanks again!

Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Right place to Initialize the findChild by object Name


shreyansjain wrote:
....

4) Once you pop out of the navigationPane,...


do 't forget to disconnect the signal from QML

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
shreyansjain
Posts: 146
Registered: ‎07-03-2013
My Device: BB 9360

Re: Right place to Initialize the findChild by object Name

Good catch Ekke!

I was doing that before but when i changed my implementation, i got rid of those lines since it worked. 

but, thats why the legend says limit the variables for introducing potential bugs

Regular Contributor
lunaplena
Posts: 205
Registered: ‎06-11-2013
My Device: Blackbery z10

Re: Right place to Initialize the findChild by object Name

Thanks

Regular Contributor
lunaplena
Posts: 205
Registered: ‎06-11-2013
My Device: Blackbery z10

Re: Right place to Initialize the findChild by object Name

How to detach the signals?

Developer
shreyansjain
Posts: 146
Registered: ‎07-03-2013
My Device: BB 9360

Re: Right place to Initialize the findChild by object Name

Pretty much the same as you connect the signal, but instead of "QObject:connect" use "QObject:disconnect" in QT.