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


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.


Reply
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi
Accepted Solution

Communicate with page below?

I've found the technique of creating a page from a component to be very useful. I can dynamically set variables within the page like so.

 

var contentpage = entryPageDefinition.createObject()
contentpage.entryId = 7

 

 Sometimes you want to do the opposite and update variables on the parent from within the created page.

 

 In this situation the parent page displays the amount of votes on each entry, the user has an option to vote from within the entry page. So when the user votes in the entry page I need to some how call a variable in the parent page to update the vote count.

 

Anyone have a suggestion on best practises to accomplish this?

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Communicate with page below?

createObject() takes an optional parent parameter. If it's set, you can reference 'parent' from the page. For example:

EntryPage.qml:
Item { id: topItem
… topItem.parent.someProperty = xxx
}

But more correct approach is declaring a signal and emitting it from child page. Subscribe to the signal on parent page:

contentpage.signalname.connect(jsFunction)

The signal must be disconnected manually when destroying the page.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 1,178
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Communicate with page below?

[ Edited ]

Depends on how you use the created page. If you push it onto a NavigationPane, then the parent attribute of the pushed page automatically points the the Nav Pane.

 

A technique I have used with success when there is no direct relationship between two objects is to hang a reference to one of them on the global Qt object, which is always present in all QML/ECMAscript files and doesn't require any import instructions. Something like this.

 

Page {
   id: myPage
   onCreationCompleted: {
      Qt.myPage = myPage;
  }
}

Now you can access myPage from any QML file as Qt.myPage.


Philipk wrote:

I've found the technique of creating a page from a component to be very useful. I can dynamically set variables within the page like so.

 

var contentpage = entryPageDefinition.createObject()
contentpage.entryId = 7

 

 Sometimes you want to do the opposite and update variables on the parent from within the created page.

 

 In this situation the parent page displays the amount of votes on each entry, the user has an option to vote from within the entry page. So when the user votes in the entry page I need to some how call a variable in the parent page to update the vote count.

 

Anyone have a suggestion on best practises to accomplish this?






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Communicate with page below?

First excuse to reference my recent KB article...Smiley Happy

 

http://supportforums.blackberry.com/t5/Native-Development-Knowledge/How-to-pass-data-to-and-from-a-Q...

 

It details how to use signals and slots for dynamic objects as Zmey rightly suggested.

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.