QML和c++的集成

QML and C++ intergration

本文关键字:集成 c++ QML      更新时间:2023-10-16

这是我在这个论坛上的第一个帖子,因为我是一个Java人,所以我刚开始开发bb10和c++。我在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);
}

现在,当从这个第二个屏幕,我试图打开第三页,它将不工作,请看到代码,告诉我他们做错了什么

您已经使用导航窗格,那么打开任何其他页面都没有问题。请看下面的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")
}

}