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
Trusted Contributor
jayvd
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus
Accepted Solution

Passing Data from a Popped Page or Sheet back to NavigationPane

Hi,

Is it possible to pass back data from a Page to a NavigationPane that pushed it??

 

1. I have a NavigationPane that opens a Page

2. in this Page, user input data and then close the Page.

3. I would like to pass some data from this Popped page and pass it back to my main NavigationPane's Page.

4. Is it possible to do this?

 

Any thoughts on how to do this? Thank you!!!

jayvdiyk.com
Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Passing Data from a Popped Page or Sheet back to NavigationPane

[ Edited ]

There are multiple ways to do this:

 

1) Declare a signal on page. Emit it when data changes:

signal signalName(string param1, string param2)   // params are optional

...

signalName('someData', 'otherData')

 

On NavigationPane after creating the page connect to that signal:

page.signalName.connect(funcname)

Before destroying the page disconnect from signal (this isn't done automatically):

page.signalName.disconnect()
page.destroy()

 Create a JavaScript function to process the signal:

function funcname(param1, param2)
{
  myProperty = param1
}

This method is convenient when the data is updated periodically. 

 

 

2) If you need to access the data only when the page is popped, then simply access the page's properties in onPopTransitionEnded handler of NavigationPane.

 

Something like:

In NavigationPane:

onPopTransitionEnded: { myProperty = page.otherProperty
page.destroy() } ... in Page.qml: Page { property alias otherProperty: someControl.someField

 

upd: If you need to pass that data to another Page, then something like this should work:

onPopTransitionEnded: {
  // 'top' property references a top page in NavigationPane
  top.myProperty = page.otherProperty
  page.destroy()
}

I'm not sure if 'top' is referencing a new top page, or the page which is being popped. In later case at() method can be used instead.

 

 3) Create a C++ class for storing the data and export it's instance to QML. Define properties in it (Q_PROPERTY). Modify them directly from QML and use QtQuick's Connection element to track changes to them (connect()/disconnect() method will work as well).

This is convenient for storing application-wide settings and reacting to changes in them.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
sorout2009
Posts: 104
Registered: ‎08-23-2012
My Device: Blackberry Z10
My Carrier: TATA DOCOMO

Re: Passing Data from a Popped Page or Sheet back to NavigationPane

For your purpose you have to make a signal in ur popped page

Page1.qml

NavigationPane {
id: navPane
Page {
property string myDataFromPage2
Container {
Button {
text: "Push New Page"
onClicked: {
navPane.push(page2.createObject());
}
}
Label {
id: lbl
text: "data from second page :"
}
}
attachedObjects: [
ComponentDefinition {
id: page2
Page2 {
onClose: {
lbl.text = data // when close signal emit from the second page , this will execute
}
}
}
]
}
}

Second Page Page2.qml

Page {
property string data
signal close
Container {
Button {
text: "Back"
onClicked: {
data = "Your data"
close(); // this will emit the sinal
navPane.pop();
}
}
}
}



By using that way you will get the data from popped page to NavigationPane's Page.
Dharmender Singh
Please use plain text.
Trusted Contributor
jayvd
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Passing Data from a Popped Page or Sheet back to NavigationPane

Thank you Zmey and sorout for the very very detailed explanation.
jayvdiyk.com
Please use plain text.