0
votes

I am new to development on BB cascades. I've created two QML Pages. I want to pass data from one QML Page to another.

I want to pass the values phonenumber(id:phonenumber) and amount ( id:amount) from mobile.qml to payment.qml.

Please anyone help me out. Thank you in advance.

Mobile.qml:

import bb.cascades 1.4
import bb.data 1.0

Page {
    onCreationCompleted: {
        getData()
        getCircle()
    }

    Container {   
        background: backgroundPaint.imagePaint
        attachedObjects: [
            ImagePaintDefinition {
                id: backgroundPaint
                imageSource: "asset:///images/background.png"
            }
        ]

        TextField {
            id:phonenumber
            hintText: "Enter Phone Number"
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)

            // On text change the label text is updated.           
            input
            {
                keyLayout: KeyLayout.Text
            }
        }

        TextField {
            id:amount
            hintText: "Enter Amount"
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)

            // On text change the label text is updated. 
            input
            {
                keyLayout: KeyLayout.Text
            }
        }

        Button {
            id: newButton
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            topMargin: ui.du(3)
            text: "Recharge"
            appearance: ControlAppearance.Primary
            color: Color.create("#F93249")
            onClicked: {
                var blogpage = goToWebView.createObject();
                navigationPane.push(blogpage);
            }
            attachedObjects: ComponentDefinition {
                id: goToWebView
                source: "payment.qml"
            }         
        }   
    }

    attachedObjects: [
        ComponentDefinition {
            id: newOptionDef
            Option {}
        }
    ] 
}

payment.qml:

import bb.cascades 1.4

Page {
    Container {      
        background: backgroundPaint.imagePaint

        attachedObjects: [
            ImagePaintDefinition {
                id: backgroundPaint
                imageSource: "asset:///images/background.png"
            }
        ]      
    }
}
3
any one help me out!kartheeki j
any one help me,i didnt get any solution :)kartheeki j

3 Answers

1
votes

Next time please post only code related to problem. As for your problem you can use parent as a proxy to access one item from another one. For example, assume we have a component:

Page.qml

import QtQuick 2.4
import QtQuick.Controls 1.2

Item {
    id:page
    width: 200
    height: 200
    property int callee
    function func() {
        txt.text = txt.text + " (changed)"
    }

    Text {
        id: txt
        anchors.centerIn: parent
        text: "click me"
        MouseArea {
            anchors.fill: parent
            onClicked: {
                page.parent.proxyFunction(page.callee);
            }
        }
    }
}

and so Item contains several Pages:

import QtQuick 2.4
import QtQuick.Window 2.0

Window {
    width: 400
    height: 200

    Row {
        anchors.fill: parent
        function proxyFunction(page) {
            children[page].func();
        }
        Page {callee: 1}
        Page {callee: 0}
    }
}

So here as you can see clicking Text in one of Pages triggers changing Text in another Page.

0
votes

In your Page add these lines:

 import bb.cascades 1.4
 import bb.data 1.0
 Page {

    id: mobilePage // ADD THIS
    property string m_amount // ADD THIS
    property string m_phoneNumber // ADD THIS

    // the rest of the code

    onClicked: { // Buttons onClick
        mobilePage.m_amount = amount.text             // ADD THIS
        mobilePage.m_phoneNumber = phonenumber.text   // ADD THIS
        var blogpage = goToWebView.createObject()
        navigationPane.push(blogpage)
    }
}

Now in payment.qml you can use this:

console.log(mobilePage.m_amount)
console.log(mobilePage.m_phoneNumber)
0
votes

You have to create a property in payment.qml at page level.

Page{
    Id: payment
    Properly string phonenumber;
    Properly string amount;
    Container{
        Label{
            Id: lblphonenumber
            text: phonenumber 
       } 
       Label{
           Id: lblamout
           text: amount
       } 

}

in your main.qml you have to do this:

onClicked: {
    var blogpage = goToWebView.createObject();
    blogpage.phonenumber = yourvalue;
    blogpage.amount = yourvalue;
    navigationPane.push(blogpage);
}

This is it :)