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: 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,523
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,028
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.
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...:smileyhappy:

 

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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.