0

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 つの問題があります。

  1. connect メソッドは、画面を変更するたびに呼び出されます (そして、起動時にのみスロットを接続したい)。
  2. ボタンをクリックすると、同じ問題が発生します。currentPage への参照がありません (ただし、その場合、top() メソッドを使用してルート ペインを保存すると、現在のページへのアクセスを取得できます)。

基本的に私の質問は次のとおりです。いつスロットを信号に接続する必要がありますか? オブジェクトが別のqmlファイルにある場合、どうすればいいですか?

qmlファイルで直接ではなく、C++でクリックされたイベントを処理したい。

4

2 に答える 2

1

エイリアスを QT として作成することもできます

Button {
    id:first_button
    text: "original text"
    onCreationComplete{
         Qt.first_qml_fitst_button = first_button
    }            
 }

そしてあなたが持つことができる2番目のフォームで

Button {
    id:second_button
    onClicked:{
         Qt.first_qml_fitst_button.text = "i change text"
    }
 }
于 2013-05-07T06:15:47.580 に答える
1

setContextProperty を使用してスロットを含む C++ オブジェクトを qml に登録し、そのスロットを DetailsPage.qml から直接呼び出します。

    ...
    Button {

        objectName: "insertBtn"
        text: qsTr("Insert Note")
        onClicked:{
             cppObject.mySlot()
        }
    }
    ...
于 2013-05-06T11:09:29.650 に答える