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
AnugrahThomas
Posts: 15
Registered: ‎07-18-2013
My Device: 9800

Calling a function in a class using attached object and id.

I am using an attached object and an id to access a cpp class method in a particular qml page. And in the on complete method of that particular attached object certain code has to be executed but the issue arises when i have to access two functions of the same cpp class .

 

I want to access the first function which is a webservice call and then "on complete " perform the second set of code. Parallel to this I also want to execute a different function using the same attached object id without entering into the on complete function which may cause an infinite loop. Please advice.

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: Calling a function in a class using attached object and id.

Could you provide some sample code demonstrating what you are trying to do?

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Contributor
AnugrahThomas
Posts: 15
Registered: ‎07-18-2013
My Device: 9800

Re: Calling a function in a class using attached object and id.

import bb.cascades 1.0
import Network.PostHttp 1.0
import Network.DbHelper 1.0
import "controls"
import my.library 1.0
import bb.system 1.0

NavigationPane {
id: navigationPane
backButtonsVisible: false
// creates one page with a label
property Page post
Page {
id: loginPage
property alias username: tfUsername.text
property alias password: tfPassword.text
property variant profiledata: {
"name": tfUsername.text,
"pass": tfPassword.text
}
signal loginPageClose()
signal onButtonClick(string username, string password)
titleBar: TitleBar {

id: addBar
title: "MetalFace"
visibility: ChromeVisibility.Visible
dismissAction: ActionItem {
title: "Sign up"
//enabled: false
onTriggered: {
// save credential

}
}
acceptAction: ActionItem {
title: qsTr("Sign in!")
onTriggered: {
progressIndicator.start();
netpost.loginWebService(tfUsername.text, tfPassword.text, false);

}
}
}
attachedObjects: [
// DbHelper{
// id: db
// },
PostHttp {
id: netpost1
},
PostHttp {
id: netpost
onComplete: {
progressIndicator.running = false;
progressIndicator.visible = false;
console.log("validDatavalue" + validData)
if (validData == 1) {
_myInstance.insert(tfUsername.text, tfPassword.text);
_myInstance.select();

// _myInstance.connectionselect();
var b = newsfeedpage.createObject();
// b.setContextProperty("_myInstance", _myInstance);
navigationPane.push(b);
// netpost1.getUserConnectionsAll();

}
else
{
myQmlToast.show();
}

}
},
ComponentDefinition {
id: newsfeedpage
source: "NewsFeed.qml"
},
SystemDialog {
id: myQmlToast
body: "Please check the username and password entered!!"

}
]

Container {
id: tab
Label {
text: "Username : "
}
TextField {
id: tfUsername
inputMode: TextFieldInputMode.EmailAddress
validator: Validator {
mode: ValidationMode.Immediate
errorMessage: "Your username must be 10 characters or fewer."

onValidate: {
if (tfUsername.text.length != 7) state = ValidationState.Valid;
else state = ValidationState.Invalid;
}
}
input.submitKey: SubmitKey.Go
}
Label {
text: "password"
}
TextField {
id: tfPassword
inputMode: TextFieldInputMode.Password
input {
submitKey: SubmitKey.Submit
onSubmitted: {

}
}
}

ActivityIndicator {
id: progressIndicator

horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
onStarted: {

}

// }

onCreationCompleted: {
progressIndicator.running = false;
}

}
}
}

}

 

See here I have called two function using posthttp attached object

 

 netpost.loginWebService(tfUsername.text, tfPassword.text, false); and

 netpost1.getUserConnectionsAll();

 

So i would like to know whether it would act as two independent attached objects or will both functions trigger the on complete section of code of the id- netpost PostHttp object.

Developer
ekke
Posts: 1,571
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Calling a function in a class using attached object and id.

to make your code readable please post it as code

there's a option 'insert code' from Rich text editor

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Contributor
AnugrahThomas
Posts: 15
Registered: ‎07-18-2013
My Device: 9800

Re: Calling a function in a class using attached object and id.

// Default empty project template
import bb.cascades 1.0
import Network.PostHttp 1.0
import Network.DbHelper 1.0
import "controls"
import my.library 1.0
import bb.system 1.0

NavigationPane {
    id: navigationPane
    backButtonsVisible: false
    // creates one page with a label
    property Page post
    Page {
        id: loginPage
        property alias username: tfUsername.text
        property alias password: tfPassword.text
        property variant profiledata: {
            "name": tfUsername.text,
            "pass": tfPassword.text
        }
        signal loginPageClose()
        signal onButtonClick(string username, string password)
        titleBar: TitleBar {

            id: addBar
            title: "MetalFace"
            visibility: ChromeVisibility.Visible
            dismissAction: ActionItem {
                title: "Sign  up"
                //enabled: false
                onTriggered: {
                    // save credential

                }
            }
            acceptAction: ActionItem {
                title: qsTr("Sign in!")
                onTriggered: {
                    progressIndicator.start();
                    netpost.loginWebService(tfUsername.text, tfPassword.text, false);
                    
                             }
            }
        }
        attachedObjects: [
//            DbHelper{
//                id: db
//            },
            PostHttp {
                id: netpost1
            },
                PostHttp {
                id: netpost
                onComplete: {
                    progressIndicator.running = false;
                    progressIndicator.visible = false;
                    console.log("validDatavalue" + validData)
                    if (validData == 1) {
                        netpost1.getUserConnectionsAll();
                        _myInstance.insert(tfUsername.text, tfPassword.text);
                        _myInstance.select();
                        

                        var b = newsfeedpage.createObject();
                        navigationPane.push(b);
                        

                    }
                    else
                    {
                        myQmlToast.show();
                    }

                }
            },
            ComponentDefinition {
                id: newsfeedpage
                source: "NewsFeed.qml"
            },
            SystemDialog {
                id: myQmlToast
                body: "Please check the username and password entered!!"
                
            }
        ]

        Container {
            id: tab
            Label {
                text: "Username : "
            }
            TextField {
                id: tfUsername
                inputMode: TextFieldInputMode.EmailAddress
                validator: Validator {
                    mode: ValidationMode.Immediate
                    errorMessage: "Your username must be 10 characters or fewer."

                    onValidate: {
                        if (tfUsername.text.length != 7) state = ValidationState.Valid;
                        else state = ValidationState.Invalid;
                    }
                }
                input.submitKey: SubmitKey.Go
            }
            Label {
                text: "password"
            }
            TextField {
                id: tfPassword
                inputMode: TextFieldInputMode.Password
                input {
                    submitKey: SubmitKey.Submit
                    onSubmitted: {

                                           }
                }
            }

            ActivityIndicator {
                id: progressIndicator

                horizontalAlignment: HorizontalAlignment.Fill
                verticalAlignment: VerticalAlignment.Fill
                onStarted: {

                }

                //                }

                onCreationCompleted: {
                    progressIndicator.running = false;
                                    }

            }
        }
    }

}