1

There are three different cpp classes in my BlackBerry 10 Cascades app

  1. Home.cpp
  2. FirstPage.cpp
  3. SecondPage.cpp

Home page has two buttons through which user can navigate to remaining pages. This page also has NavigationPane through which I can navigate to remaining pages

FirstPage has UI created in QML and SecondPage has UI created in C++ only.

How can I navigate to these pages on button click. I know about Signals and slots mechanism but dont have idea about how I can create objects of these classes and push them to Navigation Pane object.

Code snippet will be helpful

silwar
  • 6,470
  • 3
  • 46
  • 66

1 Answers1

1

You can create your navigationpane in C++ and implement your UI in QML. I am doing that. I have a class that launches my application and that creates my navigation pane (loading the page from the qml file).

Next, when you click on the button "Page1" you can call a method from C++ (see in the documentation how to expose C++ objects to QML) and in C++ launch a new page as a child of navigation pane as I suggest below

NewPage::NewPage(QObject *parent, bb::cascades::NavigationPane *navigationPane)
     : QObject(parent)

    {
        m_parent = parent;

        m_navigationPane = navigationPane;

        m_qml = bb::cascades::QmlDocument::create("asset:///qml/UserInput/newpage.qml").parent(this);

        initUI(); //Were you should initialize all of your UI

        m_page = m_qml->createRootObject<bb::cascades::Page>();
        m_page->setObjectName("PageName");
        m_navigationPane->push(m_page);

    }

This page adds a backbutton to the screen and when you click on that, the signal popFinished(bb::cascades::Page* page) is emmited. you can connect this signal to a slot in your main page (where you create the navigationpane) like I have done:

void MainPage::popFinished(bb::cascades::Page* page) {
    delete page;
}

It's easy to expose for each qml file a different c++ object. I use the MVC model, for each qml file, I have a controller and a model. the model contains all the properties that you'll need in qml. So, from the central c++ object, when I call new NewPage() I am sending the pointer to the navigation pane, so I can push the page and pop it later. In this controller you should have a model and a Getter for it, and then expose the controller to the qml before you create the page like this:

m_qml->setContextProperty("newPageController", this);

Latter in qml you can access this controller by the name of "newPageController". The methods available to qml will have to be instantiated with Q_INVOKABLE please refer to this, will help I'm sure:

http://developer.blackberry.com/native/documentation/cascades/dev/integrating_cpp_qml/

then if you want to launch another page, call a method from c++, create the page and then expose new objects to the new qml.

  • Hey Can I create separate CPP class which will handle operations of each of qml pages. If so how can I bind CPP class with particular qml when navigation page pushes it? – silwar Mar 13 '14 at 15:33
  • Are you pushing the pages from C++ or from QML? if you are in C++ you can allocate the objects to each page and pass them through a context property. If you are pushing pages from qml I think you can use the loader class, but i'm not familiarized with this mechanism. – Filipe Figueiredo Mar 13 '14 at 19:58
  • Hey Filipe, I am new to BB 10 development. Can you just brief me how can I do it in C++. I am confused about if i do it in C++ then can i use separate C++ class for each QML i designed. I have gone through web based training provided by BB but still confused about how to design project structure for BB 10 app – silwar Mar 14 '14 at 08:11
  • Hey. Please refer to my comment above again. – Filipe Figueiredo Mar 15 '14 at 12:11
  • Yes I am handling navigation through C++ only.. its working for me.. thanks – silwar Mar 18 '14 at 07:00