Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
New Contributor
Posts: 4
Registered: ‎10-09-2013
My Device: Z10
My Carrier: Dialog
Accepted Solution

Get active navigation page in blackberry 10 app

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";
                qDebug() << global::navPane->count();
//                Application::instance()::
//                navPane->push(homepage);
            }
            else
            {
                SystemToast *toast = new SystemToast(this);

                            toast->setBody("Error in home page generation!");
                            toast->setPosition(SystemUiPosition::MiddleCenter);
                            toast->show();
            }
        }

 

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

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Get active navigation page in blackberry 10 app

Welcome to the forums. Smiley Happy

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 it's even easier to create and push the page in QML and then call C++ function to perform some actions if needed.

Btw, the code you posted has a memory leak. I suggest parenting QmlDocument instance to homepage after creation:

Page *homepage = qml->createRootObject...
qml->setParent(homepage);


If you want to fix the original code, please post the full function in it's current state plus all the relevant code in other classes (initialization, parameter passing etc), because the code doesn't match the description.

Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 4
Registered: ‎10-09-2013
My Device: Z10
My Carrier: Dialog

Re: Get active navigation page in blackberry 10 app

Thanks Zmey, I'll try your way. thanks for the warm welcome. I can share the code. No worries. thought it would be burden for readers. give me couple of minutes to check your solution.
New Contributor
Posts: 4
Registered: ‎10-09-2013
My Device: Z10
My Carrier: Dialog

Re: Get active navigation page in blackberry 10 app

Hi Zmey now I get an error file:///apps/com.example.Velocity2.testDev_e_Velocity213c0cc24/native/assets//login.qml:60: Error: Unknown method parameter type: bb::cascades::NavigationPane* after doing the first way you sugested. I made parameters exactly the way you said. Could you please help?
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Get active navigation page in blackberry 10 app

[ Edited ]

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

 

Adding qmlRegisterType<NavigationPane>() 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); }

 

Another workaround is switching to QObject in parameters:

 

    Q_INVOKABLE void test(QObject *paneObj);

...

void ApplicationUI::test(QObject *paneObj)
{
	NavigationPane *pane = qobject_cast<NavigationPane *>(paneObj);

	Page *page = Page::create()
		.content(Label::create()
			.text("Test"));

	pane->push(page);
}

 

 I've attached my test project (using NavigationPane * as parameter) to this post.

 

UPD: created a JIRA ticket: https://www.blackberry.com/jira/browse/BBTEN-1801


Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 4
Registered: ‎10-09-2013
My Device: Z10
My Carrier: Dialog

Re: Get active navigation page in blackberry 10 app

Thanks loads zmey! it worked after adding the registry.