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
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None
Accepted Solution

Sending data from one QML page to another

I made an app based on QML and Python.

I am using NavigationPane as described here: https://developer.blackberry.com/cascades/reference/bb__cascades__navigationpane.html

 

Now, my question:

Since the page handle is created immediately and localy when the page gets pushed, how can I exchange information with it before or after its creation?

 

I was thinking to create the page earlier so it already exists, but do not know how this would be possible.

 

Please do not suggest any C++ solution since I am NOT using C++ for this app!

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Sending data from one QML page to another

Do you mean the page is being created dynamically, such as through a ComponentDefinition or the Qt.createComponent() call?  I assume that's what you mean by pointing to that link.

 

It might depend on the nature of the communication you want, but you can always get to the root element even from dynamically loaded pages. 

 

It seems to be a fairly widespread convention to use "id: root" on the root component, and then you could retrieve properties from it using "root.propertyName" accesses from any other component.

 

You could also use signals, connecting them in the onCreationCompleted handler of the loaded page.  For example if you defined a "signal someSignal()" in your root component, you could have your dynamic page do "root.someSignal.connect(myHandler)" and then "function myHandler() { ... }" to act as the slot.  Doing just "onSomeSignal: { ... }" might also work there.. I forget exactly when that's possible.


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!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Sending data from one QML page to another

One other simple approach is just to call a function in that page once you've created or pushed it. I sometimes add "function opening() {...}" to my Pages, then after pushing it I do "page.opening()" to tell it it is showing up onscreen.

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!
Please use plain text.
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None

Re: Sending data from one QML page to another

Hi Peter

Thank you for your quick reply.

The problem I see with your 2nd post is that "page" is only available in the onTriggered block.
I how ever would like to send data to the subpage on a later state.
As I am using PyTart ( :smileyhappy: ), I want to open the subpage, but also first have to fetch JSON data from Python. Since that data gets returned at a later state and another function, I need to be able from there to forward the data to the subpage.

As for your signal aproach, i never used signals inQML, but I will have a look into it.

Over all, I would think, hat it would be the easiest, if the variable "page" would be global. Then I simply could run page.setData(x, y, z) once the JSON data arrives.

I know there are other ways to use subpages, i.e. described here: https://developer.blackberry.com/cascades/reference/bb__cascades__sheet.html. But I could not figure out how to use them together with the NavigationPane.
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Sending data from one QML page to another

If you want it global, you can still do it that way with the properties.

// in root element
NavPaneOrWhatever {
    id: root
    property variant myPage
...

// wherever you create the dynamic Page
    onTriggered: {
        if (!root.myPage)
            root.myPage = pageDef.createObject();
        root.push(root.myPage);
    }

// if you do it that way, don't do this in the root component:
    onPopTransitionEnded: {
        root.myPage.destroy();
    }

If you want the page to be created once and never destroyed, do the if (!root.myPage) thing.  Otherwise take that out and just re-create the page each time, but then add the destroy() call to clean things up when the page is closed.


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!
Please use plain text.
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None

Re: Sending data from one QML page to another

Thank you very much.
This was exactly what I was looking for.
I tried the properties, but not with a variant :smileysad:
Please use plain text.