当我从一个qml布局到另一个qml单击按钮时,如何加载方法?因为我有一个editprofile按钮,如果我点击这个按钮,意味着我想要显示我从how服务中获得的值,如何做到这一点?有谁能给我一些建议吗?谢谢
发布于 2013-03-18 15:12:57
您需要实现此onCreationCompleted方法
onCreationCompleted: {
// call the function, that you need to show first
// first_display()
}希望这能有所帮助。!
发布于 2013-01-23 10:56:44
这听起来像是您试图将从webservice检索到的数据从一个QML视图传递到另一个视图。在导航窗格中,您可以使用createObject()从.qml文件构建UI屏幕,并将新屏幕(页面)推送到导航窗格的视图堆栈上,使您的数据可通过新创建的可见页面的UI访问。我认为这是一种更具体的描述,也是一种常见的方法。
为了传递数据,在'profileview‘QML页面的根对象( page,Container)上声明一个属性。然后,在按钮的onClicked()函数中的第一个QML文件中,将QML定义上的createObject()结果赋给变量。然后,您可以使用此变量将您的数据分配给'profileview‘页面上的属性。您的Button将如下所示:
// 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"
}
]
}下面是基于导航窗格级联示例项目的更详细的完整示例:
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": "john.doe@stackoverflow.com",
"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
}
}
}希望这能帮助你继续前进。此外,GitHub上的这些示例项目可能会有所帮助:
https://github.com/blackberry/Cascades-Samples/tree/master/quotes
https://github.com/blackberry/Cascades-Samples/tree/master/weatherguesser
发布于 2012-12-11 06:59:15
如果我理解正确的话,您希望在单击按钮时执行操作。为此,可以在QML中向Button对象添加onClicked方法。示例:
Button {
text: "View profile"
onClicked: {
myProfileInfo.visible = true;
}
}
Label {
id: myProfileInfo
text: "This is my profile"
visible: false
}https://stackoverflow.com/questions/13741217
复制相似问题