NavigationPane
テンプレート付きのウィザードを使用してブラックベリー アプリケーションを作成し、DetailsPage.qmlにいくつかのコンポーネントを追加しました ( aButton
や a など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")
}
}
}
signal を使用してボタンを接続しようとしましたpushTransactionEnded
が、2 つの問題があります。
- connect メソッドは、画面を変更するたびに呼び出されます (そして、起動時にのみスロットを接続したい)。
- ボタンをクリックすると、同じ問題が発生します。currentPage への参照がありません (ただし、その場合、top() メソッドを使用してルート ペインを保存すると、現在のページへのアクセスを取得できます)。
基本的に私の質問は次のとおりです。いつスロットを信号に接続する必要がありますか? オブジェクトが別のqmlファイルにある場合、どうすればいいですか?
qmlファイルで直接ではなく、C++でクリックされたイベントを処理したい。