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

Posts: 32
Registered: ‎01-18-2011
My Device: Curve 8900
Accepted Solution

Working with a second page

[ Edited ]



I think I'm doing everything wrong in my app,



I have a Home Page, a Login Page, and a Registry Page, so I created first the Home Page, and the Login Page:



#include "Login.hpp"


PortoVias::PortoVias(bb::cascades::Application *app) : QObject(app) { QSettings settings("CompanyX", "AppNameX"); if (settings.contains("userName") && settings.contains("password")) { } // create scene document from main.qml asset // set parent to created document to ensure it exists for the whole application lifetime QmlDocument *qml = QmlDocument::create("asset:///qml/homePage.qml"); Login *loginService = new Login(); qml->setContextProperty("loginService", loginService); // create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // set created root object as a scene app->setScene(root); }


and the Login.cpp

#include "Login.hpp"


Login::Login() {
	mNetworkAccessManager = new QNetworkAccessManager(this);

	bool result = connect(mNetworkAccessManager,
			this, SLOT(requestFinished(QNetworkReply*)));

QString Login::userName() {
	return m_userName;

void Login::setUserName(QString userName) {
	m_userName = userName;
	emit userNameChanged(m_userName);

QString Login::password() {
	return m_password;

void Login::setPassword(QString password) {
	m_password = password;
	emit passwordChanged(m_password);

void Login::initiateRequest()
	// Start the activity indicator
//	mActivityIndicator->start();

	// Create and send the network request
	QNetworkRequest request = QNetworkRequest();
	QUrl url = QUrl(loginUrl+m_userName+"&senha="+m_password);

void Login::requestFinished(QNetworkReply* reply)
	Label *errorLabel = root->findChild<Label*>("objectName");
	// Check the network reply for errors
	if (reply->error() == QNetworkReply::NoError) {
		GroupDataModel *model = new GroupDataModel(QStringList());
		JsonDataAccess jda;

		if (jda.hasError()) {
		    DataAccessError theError = jda.error();
		    if (theError.errorType() == DataAccessErrorType::SourceNotFound)
		        errorLabel->setText("Source not found: " + theError.errorMessage());
		    else if (theError.errorType() == DataAccessErrorType::ConnectionFailure)
		        errorLabel->setText("Connection failure: " + theError.errorMessage());
		    else if (theError.errorType() == DataAccessErrorType::OperationFailure)
		        errorLabel->setText("Operation failure: " + theError.errorMessage());
		} else {
		    errorLabel->setText("No error.");

		QString result =  QString::fromUtf8(reply->readAll());
		QVariantMap object = jda.loadFromBuffer(result).toMap();

		QString autorizacao = object["object"].toMap()["auth"].toString().toStdString().c_str();
		fprintf(stdout,"%s\n", autorizacao.toStdString().c_str());


		// create a ListView control and add the model to the list
		ListView *listView = new ListView();

		fprintf(stdout,"%s\n", "Problem with the Network");


But here I realised that I don't have the root in the Login.cpp, I started to think that I'm doing everything wrong...., any idea on how to get the Root from the Home.cpp to Login.cpp?

I use the qml to open from Home.qml to Login.qml

Button {
                        text: StringDef.ACCESS_MY_ACCOUNT
                        horizontalAlignment: HorizontalAlignment.Center
                        preferredWidth: 600
                        onClicked: { 
                            var page = loginPage.createObject();
                        attachedObjects: ComponentDefinition {
                            id: loginPage;
                            source: "asset:///qml/login.qml"


Regular Contributor
Posts: 53
Registered: ‎09-19-2012
My Device: 9700

Re: Working with a second page

My way: use navigation pane to push



App::App() {
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("myClass", this);
    AbstractPane *root = qml->createRootObject<AbstractPane>();

void App::pushScreen() {
	Second *sec = new Second((NavigationPane*)Application::instance()->scene(), this);
Second::Second(NavigationPane* navigationPane, QObject *parent) : QObject(parent) {
	QmlDocument *qml = QmlDocument::create("asset:///second.qml").parent(this);
	Page *root = qml->createRootObject<Page>();


Posts: 32
Registered: ‎01-18-2011
My Device: Curve 8900

Re: Working with a second page

Got this working perfectly, thanks!