2013-10-08 31 views
0

我使用qml創建了一個帶有導航窗格的QML/C++第一頁應用程序。 然後第二頁也是qml。 在第一頁的按鈕上,調用C++函數並解析第二頁,並且必須推入導航頁面。 按鈕按下我在做什麼在下面提到。在黑莓10應用程序中獲取活動導航頁面

QmlDocument *qml = QmlDocument::create("asset:///home.qml"); 
    if (!qml->hasErrors()) { 
     Page *homepage = qml->createRootObject<Page>(); 
     if (homepage) { 
      qDebug() <<"created a homepage"; 
      navPane->push(homepage); 
     }} 

但是當推動完成時,應用程序會自動終止並給出錯誤。

控制檯輸出(製作的主頁

過程304619722(Sampleapp2)終止SIGSEGV代碼= 1 fltno = 11 IP = 78f0a210(/base/usr/lib/[email protected]_ZNK2bb8cascades14NavigationPane7indexOfEPNS0_4PageE+0x707)mapaddr = 0010a210。ref = 00000010 )

我解析導航頁面指針指向第二個C++文件構造函數,並將其分配給this-> navpange變量。

我應該讓導航窗格在第一個C++文件頭中公開嗎?如果是這樣怎麼辦?

是否有無論如何我可以從第二個C++文件獲得運行應用程序的活動導航窗格而不解析它?

在此先感謝:-)

我必須使導航

回答

0

從給定的代碼,我假設主頁被未初始化。

+0

首頁是不是應用程序的第一頁。這是第二頁。顯示第一個登錄頁面。你能告訴我如何解決這個問題嗎?感謝康拉德。 –

0

黑莓論壇的Zemy回答了我。信用歸功於他。

我認爲最簡單的是通過NavigationPane從QML參數:

Q_INVOKABLE void function(NavigationPane *pane); 
... 
pane->push(homepage); 

在QML:

_app.function(navPaneId) 

但是,這得到了一個錯誤。 Zemy再次修復它。

我試圖重現這一點,也得到了同樣的錯誤信息。看來NavigationPane沒有在Cascades中正確註冊。

添加qmlRegisterType()固定它:

ApplicationUI::ApplicationUI(bb::cascades::Application *app) : 
     QObject(app) 
{ 
    // prepare the localization 
    m_pTranslator = new QTranslator(this); 
    m_pLocaleHandler = new LocaleHandler(this); 
    if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { 
     // This is an abnormal situation! Something went wrong! 
     // Add own code to recover here 
     qWarning() << "Recovering from a failed connect()"; 
    } 
    // initial load 
    onSystemLanguageChanged(); 

    //-------------------------------------- 
    qmlRegisterType<NavigationPane>(); <---------------- ADDED 
    //-------------------------------------- 

    // 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); 
    qml->setContextProperty("_app", this); 

    // Create root object for the UI 
    AbstractPane *root = qml->createRootObject<AbstractPane>(); 

    // Set created root object as the application scene 
    app->setScene(root); 
}