2013-02-26 72 views
0

我正在開發一個BB 10應用程序,其中我用C++編寫了第一頁(使用NavigationPane)。現在我想在按鈕單擊時在NavigationPane中推送另一個qml頁面。我試過下面的代碼沒有運氣如何推CML代碼頁上的按鈕點擊

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); 
if (!qml->hasErrors()) { 
    Page *page = qml->createRootObject<Page>(); 

    mRoot->push(page); 

} 

我該如何做到這一點?

+0

你是什麼main.qml的內容?你不應該從另一個文件加載你的頁面嗎? – 2013-02-26 19:56:29

+0

main.qml頁面中有一些按鈕 – silwar 2013-02-27 06:16:28

+0

是你的mRoot tabpane/navigationpane? – pranavjayadev 2013-02-27 12:26:54

回答

1

這裏是你如何可以在C使用推送頁面NavigationPane ++:

源文件:

#include <bb/cascades/Application> 
#include <bb/cascades/Button> 
#include <bb/cascades/Label> 
#include <bb/cascades/ActionItem> 
#include <bb/cascades/Container> 
#include <bb/cascades/DockLayout> 
#include <bb/cascades/TitleBar> 
#include <bb/cascades/NavigationPaneProperties> 
#include "Sandoxproject.hpp" 

using namespace bb::cascades; 

SandboxApp::SandboxApp(bb::cascades::Application *app) 
: QObject(app) 
{ 
    _navPane.reset(NavigationPane::create()); 
    Page* firstPage = createFirstPage(); 
    _navPane ->push(firstPage); 
    _secondPage.reset(createSecondPage()); 
    app->setScene(_navPane.data()); 
} 

bb::cascades::Page* SandboxApp::createFirstPage() { 
    Page* page = new Page(); 
    Container* content = new Container(); 
    TitleBar* titleBar = TitleBar::create().visibility(ChromeVisibility::Visible).title("First Page"); 
    page->setTitleBar(titleBar); 
    content->setLayout(DockLayout::create()); 
    Button* button = Button::create().text("Go to another page").horizontal(HorizontalAlignment::Center).vertical(VerticalAlignment::Center); 
    connect(button, SIGNAL(clicked()), this, SLOT(pushPage())); 
    content->add(button); 
    page->setContent(content); 
    return page; 
} 

bb::cascades::Page* SandboxApp::createSecondPage() { 
    Page* page = new Page(); 
    TitleBar* titleBar = TitleBar::create().visibility(ChromeVisibility::Visible).title("Second Page"); 
    page->setTitleBar(titleBar); 
    ActionItem* backAction = ActionItem::create(); 
    connect(backAction, SIGNAL(triggered()), _navPane.data(), SLOT(pop())); 
    page->setPaneProperties(NavigationPaneProperties::create().backButton(backAction)); 
    Container* content = new Container(); 
    content->setLayout(DockLayout::create()); 
    content->add(Label::create().text("This is the second page").horizontal(HorizontalAlignment::Center).vertical(VerticalAlignment::Center)); 
    page->setContent(content); 
    return page; 
} 

void SandboxApp::pushPage() { 
    qDebug("pushing another page..."); 
    _navPane->push(_secondPage.data()); 
} 

頭文件

#ifndef Sandoxproject_HPP_ 
#define Sandoxproject_HPP_ 

#include <bb/cascades/NavigationPane> 
#include <bb/cascades/Page> 
#include <QObject> 

namespace bb { namespace cascades { class Application; }} 

class SandboxApp : public QObject 
{ 
    Q_OBJECT 
public: 
    SandboxApp(bb::cascades::Application *app); 
    virtual ~SandboxApp() {} 

private slots: 
    void pushPage(); 

private: 
    bb::cascades::Page* createFirstPage(); 
    bb::cascades::Page* createSecondPage(); 

    QScopedPointer<bb::cascades::NavigationPane> _navPane; 
    QScopedPointer<bb::cascades::Page> _secondPage; 

    Q_DISABLE_COPY(SandboxApp); 
}; 


#endif /* Sandoxproject_HPP_ */