【发布时间】:2013-05-04 09:50:04
【问题描述】:
我使用带有NavigationPane 模板的向导创建了一个黑莓应用程序,并在DetailsPage.qml 中添加了一些组件(如Button 和TextField)。
我想在 DetailsPage.qml 中的按钮上连接一个插槽功能,当单击该功能时,将文本读入同一页面上的 TextArea。
我的问题是,当应用程序启动时,加载的 qml 是 main.qml。
如果我尝试在 DetailsPage.qml findChild 上获取对对象的引用,则返回 0x0,因为它找不到它。
main.qml 文件为:
// Navigation pane project template
import bb.cascades 1.0
NavigationPane {
id: navigationPane
Page {
// page with a picture thumbnail
Container {
background: Color.Black
layout: DockLayout {
}
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("New todo")
imageSource: "asset:///images/picture1thumb.png"
onClicked: {
// show detail page when the button is clicked
var page = getSecondPage();
console.debug("pushing detail " + page)
navigationPane.push(page);
}
property Page secondPage
function getSecondPage() {
if (! secondPage) {
secondPage = secondPageDefinition.createObject();
}
return secondPage;
}
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
objectName: "secondPageDefinition"
source: "DetailsPage.qml"
}
]
}
}
}
onCreationCompleted: {
// this slot is called when declarative scene is created
// write post creation initialization here
console.log("NavigationPane - onCreationCompleted()");
// enable layout to adapt to the device rotation
// don't forget to enable screen rotation in bar-bescriptor.xml (Application->Orientation->Auto-orient)
OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
}
}
detailsPage.qml 文件为:
// Navigation pane project template
import bb.cascades 1.0
Page {
// page with a picture detail
id: pgDetail
objectName: "pgDetail"
actions: [
// create navigation panel actions here
ActionItem {
title: qsTr("Break")
onTriggered: {
imgView.imageSource = "asset:///images/picture1br.png"
}
}
]
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
onTriggered: {
// define what happens when back button is pressed here
// in this case is closed the detail page
navigationPane.pop()
}
}
}
Container {
background: Color.Black
Label {
text: qsTr("Page 2")
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base: SystemDefaults.TextStyles.TitleText
color: Color.Yellow
}
}
ImageView {
id: imgView
imageSource: "asset:///images/picture1.png"
horizontalAlignment: HorizontalAlignment.Center
}
Label {
text: qsTr("Picture description")
horizontalAlignment: HorizontalAlignment.Center
}
TextArea {
objectName: "noteText"
}
Button {
objectName: "insertBtn"
text: qsTr("Insert Note")
}
}
}
我尝试使用信号pushTransactionEnded连接按钮,但有两个问题:
- 每次切换屏幕时都会调用 connect 方法(我只想在启动时连接插槽)。
- 当我点击按钮时,我有同样的问题,我没有引用 currentPage(但如果我在这种情况下保存根窗格,使用 top() 方法,我可以获得对当前页面的访问页)
所以基本上我的问题是: 我什么时候必须将我的插槽连接到信号? 如果对象位于不同的 qml 文件中,我该怎么做?
我想处理 C++ 上的点击事件,而不是直接在 qml 文件中。
【问题讨论】:
标签: c++ qml blackberry-cascades