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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

GroupDataModel is not working on data model?

Hi All,


While displaying GroupDataModel on ListView is not displaying data.

Below is my code.


 * GetLeadsHttp.h
 *  Created on: 19-Mar-2013
 *      Author: dell


#include <bb/data/JsonDataAccess>
#include <QString>
#include <QtCore/QObject>
#include <bb/cascades/GroupDataModel>
#include <bb/cascades/QListDataModel>
#include <bb/cascades/ListView>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/ListView>
#include <bb/cascades/ActivityIndicator>
#include <QNetworkAccessManager>
#include <bb/system/InvokeManager>
#include <bb/system/InvokeRequest>
#include <bb/system/InvokeTargetReply>
#include <bb/cascades/Page>
#include <bb/cascades/TextField>
using namespace bb::data;
using namespace bb::cascades;
class QNetworkAccessManager;

class GetLeadsHttp: public QObject {

	Q_PROPERTY(bb::cascades::GroupDataModel *dataModel READ dataModel CONSTANT);
	GetLeadsHttp(QObject* parent = 0);

public Q_SLOTS:
	void post(const QString &body, const QString &token);
	//void leadCall(const QString &body);

private Q_SLOTS:

	void onGetReply();
	void onInvokeResult();
	//void filterDataModel(QString filterText);


	bb::cascades::GroupDataModel* dataModel() const;

	ActivityIndicator *mActivityIndicator;
	QDeclarativePropertyMap* propertyMap;
	bb::cascades::GroupDataModel* m_dataModel;
	bb::cascades::GroupDataModel* d_dataModel;
	ListView* leads_list;
	QListDataModel<QVariantMap>* listDataModel;
    Page* leadPage;
    TextField* txt_field;
	void setIndicator(ActivityIndicator *indicator);
	// bb::system::InvokeManager *m_invokeManager;
    bb::system::InvokeTargetReply *_invokeTargetReply;


	QNetworkAccessManager* m_networkAccessManager;

#endif /* GETLEADSHTTP_H_ */



bb::cascades::GroupDataModel* GetLeadsHttp::dataModel() const
    return m_dataModel;
void GetLeadsHttp::post(const QString &body,const QString &auth_token)

	m_dataModel=new GroupDataModel(QStringList() << "Firstname"<< "Lastname" << "Company" << "NextFollowUpdate" << "leadRating" <<"SurveyAnswer3"
			<<"SurveyAnswer2" <<"SurveyAnswer1" <<"state" <<"ScanTime" <<"RecordId" <<"Phone" <<"Notes" <<"FollowupTypes" <<"eventTile" <<"EventId" <<"Email" <<"Designation"
			<<"City" <<"Barcodeid" <<"Barcode");

    const QUrl url("https://cs5.salesforce.com/services/apexrest/getLeads?");

    QNetworkRequest request(url);

   // request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
    request.setRawHeader(QString("Authorization").toUtf8(),QString("OAuth "+auth_token).toUtf8());

    if (AppSettings::isUsingHttps()) {

        QSslConfiguration config = request.sslConfiguration();

    QNetworkReply* reply = m_networkAccessManager->post(request, body.toAscii());
    connect(reply, SIGNAL(finished()), this, SLOT(onGetReply()));

void GetLeadsHttp::onGetReply()
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    JsonDataAccess jda;

    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
        } else {
            response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
            qDebug() << response;


    if (response.trimmed().isEmpty()) {
        response = tr("Unable to retrieve post response");

    qDebug() << "Get Leads data..."+response;
    QVariantList lobbyJson = jda.loadFromBuffer(response).value<QVariantList>();
   qDebug() << "%%%%%%%%%%% 1 %%%%%%%%";
  for(int i=0; i<lobbyJson.size(); i++ ){

	   QVariantMap postFeed = lobbyJson.at(i).toMap();



import bb.cascades 1.0
import "Common"
import Network.PostHttp 1.0
import Network.GetHttp 1.0
import Network.GetLeadsHttp 1.0
import "controls"
import my.library 1.0
import bb.system 1.0

// the third tab has its own pane which will be automatically
// set as the active pane when the tab becomes active

Page {
    id: defaultPane
    actions: [
        // An action item that calls the C++ function that retrieves
        // the contact list
        ActionItem {
            title: "Scan"
            onTriggered: leadValue.post("EventId=&UserId=" + _httpsample.getUserID, _httpsample.getAccessToken)
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///images/scan_unfocus_mode.png"
        ActionItem {
            title: "Leads"
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///images/lead_unfocus_mode.png"
    Container {
        id: leadContainer
        background: Color.create("#F4F4EE")
        layout: StackLayout {
        Container {
            background: Color.create("#0A6FA6")
            preferredWidth: 768.0
            preferredHeight: 110
            // maxHeight: 140
            topPadding: 10.0
            layout: DockLayout {
            Container {
                preferredWidth: 220
                leftPadding: 20
                topPadding: 20
                horizontalAlignment: HorizontalAlignment.Left
                Label {
                    id: leadCount
                    text: ""
                    textStyle.fontSize: FontSize.Small
                    textStyle.color: Color.White
                    textStyle.fontWeight: FontWeight.Bold

                    //textStyle.textAlign: TextAlign.Right
            Container {
                // preferredWidth: 0
                // preferredHeight: 0
                // horizontalAlignment: HorizontalAlignment.Left
                leftPadding: 270.0
                //topPadding: 10
                //maxHeight: 50.0
                TextField {
                    id: filterList
                    objectName: "txtSrch"
                    hintText: "Search Lead"
                    textStyle.fontSize: FontSize.XSmall
                    preferredWidth: 480.0
                    horizontalAlignment: HorizontalAlignment.Center
                    onTextChanging: {
        // A list that has two list item components, one for a header
        // and one for contact names. The list has an object name so
        // that we can set the data model from C++.
        Container {
            id: containerList

            // topPadding: 20.0
           // background: Color.create("#F4F4EE")
            topPadding: 250.0
            ActivityIndicator {
              id: leadProgressbar
             //objectName: "indicator1"
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                preferredWidth: 200
                preferredHeight: 200
               // running: true
             //onStarted: leadValue.post("EventId=&UserId=" + _httpsample.getUserID, _httpsample.getAccessToken)
                // onStopped: containerList.topPadding = 0;
            ListView {
                dataModel: leadValue.dataModel
                listItemComponents: ListItemComponent {
                    type: "item"

                    StandardListItem {
                        title: qsTr("%1, %2").arg(ListItemData.Firstname).arg(ListItemData.Lastname)
        // The activity indicator has an object name set so that
        // we can start and stop it from C++
    attachedObjects: [
        GetLeadsHttp {
            id: leadValue
        ComponentDefinition {
            id: leadDetails
            source: "LeadDetailsPage.qml"
        SystemDialog {
            id: emailValidation
            title: "Alert!"
            body: "Please enter a valid Email Id"

 While click on scan action i am calling post() method of GetLeadHttp, everything is looking fine but data is not displaying on list view. Please suggest me where i am wrong.


New Developer
Posts: 12
Registered: ‎09-23-2008
My Device: Dev Alpha B
My Carrier: Telcel

Re: GroupDataModel is not working on data model?


I think you should check the Callapizza example on BlackBerry GitHub. The example use a list on qml and the data model con C++.


this is the link for the source code.





Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: GroupDataModel is not working on data model?

Thanks for reply, right now i am following AddressBook sample on Blackberry GitHub.