Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top