applicationui.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 ++文件但是如果堆栈增加那么我们应该如何做到这一点。
-------请让我知道如果你不理解我的问题----------------
答案 0 :(得分:0)
您可以使用以下方法在.qml文件的applicationui.cpp中使用call函数:
qml-&gt; setContextProperty(“_ app”,this);
如果您想使用不同的.cpp文件,可以使用:
DetailPage detailPage = new DetailPage();
qml->setContextProperty("_detail", detailPage);
在.qml文件中,您可以通过_app.nameFunction() or _detail.nameFunction()
答案 1 :(得分:0)
从我的github示例中获取示例应用程序以供查询....
https://github.com/svmrajesh/BB-10-Cascades/tree/master/MY%20APPS/stackNavigation
请参阅以下帖子以获得解决方案
what is this control and how to use it in BB 10 cascades for navigation