separate .cpp file for every qml in blackberry 10

418 views Asked by At
  1. In my application i am using navigation pane. and i want to make separate files for every QML Let suppose this is my file

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.Here i am loading main.qml which is like this

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.And in this file I am calling "DetailsPage.qml" file which look like this

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"
    }   
    }
}

step 1: how to create seperate .cpp and .hh file for DetailsPage.qml

step 2: I want this becasue i am doing networking operations in .cpp and .hh and designing in QML.

step 3: The main reason i am confuse here is if i navigate from QML then total control is with QML and vice versa. On stack first qml can recognize its c++ file but if stack increases then how we should do that.

-------Please let me know If you don't understand my problem----------------


2

There are 2 answers

0
Rajesh Loganathan On
2
maxximus On

You can use call function in applicationui.cpp from .qml file by using :

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

If you want using different file .cpp you can use :

DetailPage detailPage = new DetailPage();

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

In .qml file, you can call function from .cpp by _app.nameFunction() or _detail.nameFunction()