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
Developer
Posts: 61
Registered: ‎10-16-2013
My Device: Z10
My Carrier: vodaphone
Accepted Solution

navigationPane is not acessable in c++

i have a file tabs.qml

 

import bb.cascades 1.0

/**
* Top level widget, TabbedPane that helps us navigate to,
* Home, Search, Call and Locations.
*/
TabbedPane {
id: tabbedPane
showTabsOnActionBar: true

// navigates us to the Bookmarks tab.
Tab {
id: tabHome
description: "Home"
title: qsTr("Home")
imageSource: "asset:///images/TabHome.png"

Home {
id : home
}

}

// navigates us to the Search tab.
Tab {
id: tabSearch
description: "Search"
title: qsTr("Search")
imageSource: "asset:///images/TabSearch.png"
}

// navigates us to the call tab.
Tab {
id: tabCall
description: qsTr("call")
title: "Call"
imageSource: "asset:///images/TabCall.png"
}

// navigates us to the location tab.
Tab {
id: tabLocation
description: qsTr("Location")
title: "Location"
imageSource: "asset:///images/TabLocations.png"
}
}

 

 

then i have a home.qml

 

import bb.cascades 1.0
import cb.home 1.0
import cb.item 1.0
NavigationPane {

id: navigationPane
objectName: "np"

Page {
HomeSample {
id: tabhome
objectName: "home"
}

}

attachedObjects: ComponentDefinition {
id: settingsDefinition
Item {
}
}

}

 

and in homesample.cpp i want to access the navigation pane in home.qml

 

/*
* HomeSample.cpp
*
* Created on: Nov 6, 2013
* Author: charuta
*/

#include "HomeSample.h"
#include <bb/cascades/Application>
#include <QDebug>

HomeSample::HomeSample() {

_npNavigationPane = Application::instance()->scene()->findChild<NavigationPane *>("np");
if(_npNavigationPane == NULL)
qDebug() << "NULL*********************" ; // gets printed.
else
qDebug() << "NOTTTTTTTTTT NULLL" ;

}

HomeSample::~HomeSample() {

}

 

 

my main.cpp has this line :

qmlRegisterType<HomeSample>("cb.home",1,0,"HomeSample");

 

what is it that i m missing??

Please Help !!

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: navigationPane is not acessable in c++

[ Edited ]

Are you include <bb/cascades/NavigationPane> ?


EDIT:

I tried get NavigationPane in C++. And i get NULL object when i use 

NavigationPane *pane = Application::instance()->scene()->findChild<NavigationPane*>("naviPane"); // Maybe is a bug? Still get NULL object

 but when i use

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
//Create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();

NavigationPane *pane = root->findChild<NavigationPane*>("naviPane");

 then is everything OK. Try it Smiley Wink



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Highlighted
Developer
Posts: 61
Registered: ‎10-16-2013
My Device: Z10
My Carrier: vodaphone

Re: navigationPane is not acessable in c++

 main.qml never comes in picture, in applicationui.cpp this is wat i have done :

  QmlDocument *qml = QmlDocument::create("asset:///qml/Tabs.qml").parent(this);

 

tabs creates home.qml that in turn creates HomeSample.cpp

Developer
Posts: 61
Registered: ‎10-16-2013
My Device: Z10
My Carrier: vodaphone

Re: navigationPane is not acessable in c++

sloved the problem myself!!

the issue was, _npNavigationPane = Application::instance()->scene()->findChild<NavigationPane *>("navigationPaneHome"); was getting called before the QML was loaded.

i.e., i was trying to access the object of NavigationPane, even before it was created.