2
  1. 在我的应用程序中,我正在使用导航窗格。我想为每个 QML 制作单独的文件假设这是我的文件

应用程序ui.cpp

    // initial load    
    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    app->setScene(root);

2.这里我正在加载main.qml是这样的

import bb.cascades 1.0

NavigationPane {
    id: navigationPane

    Page {
        titleBar: TitleBar {
            // Localized text with the dynamic translation and locale updates support
            title: qsTr("Page 1") + Retranslate.onLocaleOrLanguageChanged
        }

        Container {
        }

        actions: ActionItem {
            title: qsTr("Second page") + Retranslate.onLocaleOrLanguageChanged
            ActionBar.placement: ActionBarPlacement.OnBar

            onTriggered: {
                // A second Page is created and pushed when this action is triggered.
                navigationPane.push(secondPageDefinition.createObject());
            }
        }
    }

    attachedObjects: [
        // Definition of the second Page, used to dynamically create the Page above.
        ComponentDefinition {
            id: secondPageDefinition
            source: "DetailsPage.qml"
        }
    ]

    onPopTransitionEnded: {
        // Destroy the popped Page once the back transition has ended.
        page.destroy();
    }
}

3.在这个文件中,我调用“DetailsPage.qml”文件,看起来像这样

import bb.cascades 1.0

Page {
    titleBar: TitleBar {
        // Localized text with the dynamic translation and locale updates support
        title: qsTr("Second Page") + Retranslate.onLocaleOrLanguageChanged
    }
    Container {
    Label {
        id: msgLabel
        objectName: "msgLabel"
    }   
    }
}

第 1 步:如何为 DetailsPage.qml 创建单独的 .cpp 和 .hh 文件

第 2 步:我想要这个,因为我在 .cpp 和 .hh 中进行网络操作并在 QML 中进行设计。

第 3 步:我在这里感到困惑的主要原因是,如果我从 QML 导航,那么完全控制权在 QML,反之亦然。在堆栈上,qml 首先可以识别它的 c++ 文件,但如果堆栈增加,那么我们应该如何做到这一点。

--------如果你不明白我的问题,请告诉我----


4

2 回答 2

0

您可以使用 .qml 文件中的 applicationui.cpp 中的调用函数,方法是:

qml->setContextProperty("_app", this);

如果你想使用不同的文件 .cpp 你可以使用:

DetailPage detailPage = new DetailPage();

qml->setContextProperty("_detail", detailPage);

在 .qml 文件中,您可以通过 .cpp 调用函数_app.nameFunction() or _detail.nameFunction()

于 2013-08-19T07:47:08.323 回答
0
  1. 从我的 github 示例中获取示例应用程序以供您查询....

    https://github.com/svmrajesh/BB-10-Cascades/tree/master/MY%20APPS/stackNavigation

  2. 请参阅以下帖子以获取解决方案

    这个控件是什么以及如何在 BB 10 级联中使用它进行导航

于 2013-09-04T12:42:56.407 回答