Pregunta

I'm making an app with QML/c++ first page with navigation pane is created with qml. Then the second page is also qml. On a button press of first page a c++ function is invoked and parsed the second page and have to push to navigation page. what I'm doing in button press is mentioned below.

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

But when pushing is done application terminates automatically giving an error.

console output is (created a homepage

Process 304619722 (Sampleapp2) terminated SIGSEGV code=1 fltno=11 ip=78f0a210(/base/usr/lib/libbbcascades.so.1@_ZNK2bb8cascades14NavigationPane7indexOfEPNS0_4PageE+0x707) mapaddr=0010a210. ref=00000010 )

I'm parsing the navigation page pointer to the second c++ file constructor and assigning it to a this->navpange variable.

Should I make navigation pane public in first c++ file header? if so how to do it?

Is there anyway I can get active navigation pane of running app from second c++ file without parsing it?

Thanks in advance :-)

Do I have to make the navigation

¿Fue útil?

Solución 2

Zemy from blackberry forums answered me. Credit goes to him.

I think easiest is to pass the NavigationPane as a parameter from QML:

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

In QML:

_app.function(navPaneId)

But this got an error. Zemy again fixed it.

I've tried to reproduce this and also got the same error message. It seems NavigationPane isn't properly registered in Cascades.

Adding qmlRegisterType() fixed it:

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);
}

Otros consejos

From the code given, I assume that homepage is unitialized.

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