QML和C ++集成

时间:2013-06-18 11:30:20

标签: c++ qt blackberry qt4 blackberry-10

这是我在这个论坛上的第一篇文章,刚开始BB 10开发,还有C ++,因为我是一个Java人员。我在QML和C ++集成方面遇到了一些问题

这就是我要做的事情:

我有登录页面,在登录按钮上单击我的新页面(这是一个导航窗格)打开没有任何问题这里是我使用的方法

void Integration:penNextPage() {
    printLog("-- open second page (a navigation pane ");
    new SecondPageHndlr (appRefrence);
}

以下是我在SecondPageHndlr类中所做的事情:

SecondPageHndlr.cpp
#include "SecondPageHndlr.hpp"
#include "ThirdPageHndlr.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/NavigationPane>
#include <bb/cascades/Page>
#include <bb/cascades/Sheet>
#include <QObject>
#include <QIODevice>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
using namespace bb::cascades;
SecondPageHndlr::SecondPageHndlr(bb::cascades::Application *app)
: QObject(app){
    try{
            QmlDocument *secondQml = QmlDocument::create("asset:///SecondPage.qml");
            if (!secondQml->hasErrors()) {
                NavigationPane* page = secondQml->createRootObject<NavigationPane>();
                if (page)
                {
                    printLog("second page view . page is not  null ");
                    //make this c++ file accessable from the dashboardviewn.qml
                    pane = page;
                    secondQml->setContextProperty("second", this );
                    app->setScene(page);
                }
                else
                    printLog("page is null ");
            }
            else
                printLog("Error in second page view QML");
        }
        catch (std::exception& e)
        {
            printLog("-------- Exception");
            std::cout << "Exception: " << e.what();
        }
}
void SecondPageHndlr::showThirdScreen(){
    printLog("-- open Third page (a navigation pane pushes a new page");
    new ThirdPageHndlr (pane);
}
void SecondPageHndlr::printLog(const char *str){
    cout <<"\n" << str ;
    printf("" ,1);
    fflush(stdout);
}

现在,当我从第二个屏幕开始尝试打开第三个页面时,它根本无法正常工作,请查看代码并告诉我他们做错了什么

1 个答案:

答案 0 :(得分:0)

您已经在使用导航窗格,因此打开任何其他页面都没有问题。请参阅以下qml代码

import bb.cascades 1.0

NavigationPane {
    id: navigationPane
    Page {
        // page with a picture thumbnail
        Container {
            background: Color.Gray
            layout: DockLayout {
            }
            Button {
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                text: qsTr("Show detail")
                onClicked: {
                    // show detail page when the button is clicked
                    var page = secondPageDefinition.createObject();
                    console.debug("pushing detail " + page)
                    navigationPane.push(page);
                }
                  attachedObjects: [
                    ComponentDefinition {
                        id: secondPageDefinition
                        source: "DetailsPage.qml"
                    }
                ]
            }
        }
    }

}

DetailsPage.qml

Page{
  Label{
text: qsTr("Second Page")
}

}