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: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel
Accepted Solution

How to access QML object to display the error message.

Hi All,

 

I have one query. I have made a login screen ("asset:///qml/screenLogin.qml") . OB login button click i sendt request to server which send XML data as a response.

 

After that i am parsing the XML data using Login Handler. Code is Below: 

 

/*
 * LoginHandler.cpp
 *
 *  Created on: Jan 15, 2013
 *      Author: Ekansh
 */

/*Parsing the Login Response Structure.

 <kayako_staffapi>
 <status>
 <![CDATA[ 1 ]]>
 </status>
 <error/>
 <version>
 <![CDATA[ 4.51.1891 ]]>
 </version>
 <sessionid>
 <![CDATA[ 5t8hzmxq14jv9npkoy8e9oh8nobt9p8y ]]>
 </sessionid>
 <sessiontimeout>
 <![CDATA[ 21600 ]]>
 </sessiontimeout>
 <staffid>
 <![CDATA[ 1 ]]>
 </staffid>
 </kayako_staffapi>

 */

//#include <QDebug>
#include "loginhandler.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/controls/page.h>
#include <bb/cascades/XmlDataModel>`
#include <bb/cascades/TextField>
#include <QObject>

namespace bb {
namespace cascades {

LoginHandler::LoginHandler() {
	// TODO Auto-generated constructor stub

}

LoginHandler::~LoginHandler() {
	// TODO Auto-generated destructor stub
}

bool LoginHandler::startDocument() {
	qDebug() << "Start of the document.";
	return true;
}

bool LoginHandler::endDocument() {
	qDebug() << "End of the document.";
	return true;
}

bool LoginHandler::startElement(const QString &namespaceURI,
		const QString &localName, const QString &qName,
		const QXmlAttributes &atts) {
	qDebug() << "Start of element" << qName;
	for (int i = 0; i < atts.length(); ++i)
		qDebug() << "  " << atts.qName(i) << "=" << atts.value(i);

	return true;
}

bool LoginHandler::endElement(const QString &namespaceURI,
		const QString &localName, const QString &qName) {
	qDebug() << "End of element" << qName;

	if (qName == "sessionid") {
		sessionid = tagValue;
		qDebug() << "sessionid:: " << sessionid;
	} else if (qName == "error") {
		error = tagValue;
		qDebug() << "error:: " << error;


		/*QmlDocument *qml = QmlDocument::create("asset:///qml/screenLogin.qml");
		//Container *root = qml->createRootObject<Container>();
		AbstractPane *root = qml->createRootObject<AbstractPane>();
		QObject *newLabel = root->findChild<QObject*>("errorObject");

		if (newLabel)
			newLabel->setProperty("text", "error");*/

	}
	return true;
}

bool LoginHandler::fatalError(const QXmlParseException & exception) {
	qWarning()
			<< QString("Fatal error on line %1, column %2: %3").arg(
					exception.lineNumber()).arg(exception.columnNumber()).arg(
					exception.message());

	return false;
}

bool LoginHandler::characters(const QString &str) {
	qDebug() << "Characters" << str;
	tagValue = str;
	return true;
}
} /* namespace cascades */
} /* namespace bb */

 

 

When i put wrong credentials i want some error message to be displayed on login QML.

 

See the code at EndElement method of this handler. 

 

But i am not able set the error message on login QML.

 

Please help.

Developer
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810
My Carrier: Verizon

Re: How to access QML object to display the error message.

You can set the label with the message like below. Provided you have specified the label in qml with the same objectname "errorLbl"

QObject *lblError = bb::cascades::Application::instance()->findChild<QObject*>("errorLbl");
    if (lblError)
        lblError->setProperty("text", "error");

 -Dishooom

 

Hope this helps... :Angel:

 

Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: How to access QML object to display the error message.

Hi Dishoom,


It got worked. Thanks a lot. :smileyhappy: :smileyhappy:
New Developer
Posts: 11
Registered: ‎07-10-2014
My Device: BlackBerry Z10
My Carrier: idea

Re: How to access QML object to display the error message.

hi,

can u send complete login code and receiving service am unable to writing the code if u send il practise and and i will learn

login.cpp

login.hpp

login.qml

am a learner please help me

New Developer
Posts: 11
Registered: ‎07-10-2014
My Device: BlackBerry Z10
My Carrier: idea

Re: How to access QML object to display the error message.

hi,

can u send complete login code and receiving service am unable to writing the code if u send il practise and and i will learn

login.cpp

login.hpp

login.qml

am a learner please help me

mail me the code

ch.narender.reddi@gmail.com

please