0
votes

How to load a method when i click a button from one qml layout to other qml? as am having a editprofile button if i click the button means i want to show the values ,which i got from the webservice how to do this? can anyone send some idea.? Thanks

3
can you be more precise? Didn't get your question.Nishant Shah

3 Answers

2
votes

you need to implement this onCreationCompleted method

    onCreationCompleted: {
   // call the function, that you need to show first
   // first_display()
   }

Hope this helps.!!!

2
votes

It sounds like you are trying to pass data retrieved from a webservice from one QML view to another. A Navigation pane where you use the createObject() to build a UI screen from a .qml file and push the new screen (page) onto the view stack of the Navigation Pane, with your data accessible to the UI of the newly created and visible page is a more concrete description I think, and a common way to do this.

In order to pass your data around, declare a property on the root object (Page, Container) of your 'profileview' QML page. Then, in your first QML file in your button's onClicked() function assign to variable the result of createObject() on the QML definition. You can then use this variable to assign your data to the property on the 'profileview' page. Your Button would look something like this:

// Assume you have a Navigation Pane called navPane
// You also have to define a component for your QML file
Button {
  text: "View profile"
  onClicked: {
    var profilePage = profileDefinition.createObject();
    profilePage.myData = webserviceData;
    navPane.push(profilePage);
  }
  attachedObjects: [
    ComponentDefinition {
      id: profileDefinition
      source: "profilePage.qml"
    }
  ]
}

A more detailed full example based on the Navigation Pane Cascades sample project is below:

main.qml

// Navigation pane project template
import bb.cascades 1.0

NavigationPane {
id: navPane

// This property holds and tracks the created profile page
property Page profilePage

/* This property holds some sample webservice data, in practice 
 * you would load this from the webservice
 */
property variant webserviceData: {
    "name": "John Doe",
    "email": "[email protected]",
    "twitter": "@johndoe"
}
Page {
    // page with a button to display profile
    Container {
        layout: DockLayout {
        }
        Label {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Top
            text: webserviceData.name
        }
        Button {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            text: qsTr("Show Profile")
            onClicked: {
                // show detail page when the button is clicked
                profilePage = profileDefinition.createObject();
                profilePage.myProfileData = webserviceData;
                navPane.push(profilePage);
            }
            attachedObjects: [
                ComponentDefinition {
                    id: profileDefinition
                    source: "profilePage.qml"
                }
            ]
        }
    }
}
onPopTransitionEnded: {
    // Clean up any pages that have been popped, to avoid memory leaks
    if (profilePage == page) {
        page.destroy();
    }
}
}

profilePage.qml

// Navigation pane project template
import bb.cascades 1.0

Page {

/* Our data property
 * Note: A variant is a QVariant Qt type, so it can easily handle different 
 * data types, in our case it is a map.
 * Without the braces to denote that it is an object you will get a TypeError
 * from QML at runtime 
 */
property variant myProfileData: { /*empty object*/ }

// page with profile details
paneProperties: NavigationPaneProperties {
    backButton: ActionItem {
        onTriggered: {
            // Pop this page off the stack and go back
            navPane.pop();
        }
    }
}
Container {
    Label {
        text: qsTr("Profile Page")
        horizontalAlignment: HorizontalAlignment.Center
        textStyle {
            base: SystemDefaults.TextStyles.TitleText
            color: Color.Blue
        }
    }
    Label {
        text: "Name:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.name
        horizontalAlignment: HorizontalAlignment.Center
    }
    Label {
        text: "Email:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.email
        horizontalAlignment: HorizontalAlignment.Center
    }
    Label {
        text: "Twitter:"
        horizontalAlignment: HorizontalAlignment.Left
    }
    TextField {
        text: myProfileData.twitter
        horizontalAlignment: HorizontalAlignment.Center
    }
}
}

Hopefully that helps get you going. Also, these sample projects on GitHub may help:

https://github.com/blackberry/Cascades-Samples/tree/master/quotes

https://github.com/blackberry/Cascades-Samples/tree/master/weatherguesser

1
votes

If I understand you correctly you want to perform an action when you click a button. To do this you can add the onClicked method to your Button object in QML. Example:

Button {
    text: "View profile"
    onClicked: {
        myProfileInfo.visible = true;
    }
}

Label {
    id: myProfileInfo
    text: "This is my profile"
    visible: false
}