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
Regular Contributor
umairqureshi_6
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

parsing xml into groupdatamodel and displaying in listview

hi

i am using qtsoap library for using webservice

 

i have connected the response and request to server successfully

 

now i want to parse xml, and save it to group data model, and then want to display it in listview in qml file

 

i am using the sample soapxml for it

 

here is my code

 

void WeatherService::onServiceResponse()
{
    // Get the response, check for error.
    const QtSoapMessage& response = m_soap.getResponse();
    qDebug() << "Test application 123\n" + response.toXmlString();
    qWarning()<<"my warning information";
    if (response.isFault()) {
        m_error = tr("Query failed: %1").arg(response.faultString().value().toString());
        emit statusChanged();

        m_active = false;
        emit activeChanged();

        emit complete();
        return;
    }


    // Extract the return value from this method response, check for
    // errors.
    const QtSoapType& responseValue = response.returnValue();
    QXmlStreamReader xml;
    QList<QMap<QString, QVariant> > feeds;
    qDebug() << "Test Response Value\n" + responseValue.toString() ;

    xml.addData(responseValue.toString()); //xml is a QXmlStreamReader
	 pModel = new GroupDataModel();

	 // Load the XML data from local file
	 XmlDataAccess xda;
	 QVariant list = xda.load(responseValue.toString(),"/root/news/item/");

	 // Add the data to the model
	 pModel->insertList(list.value<QVariantList>());
    	qDebug() << "List value qvariant" +list.toString();




    while (!xml.atEnd())
      {
      xml.readNext();
      if (xml.isStartElement())
      {
         if (xml.name() == "title")
         {


        	 m_succeeded = true;
        	         	        m_error.clear();

        	 QString aux(QString::fromUtf8(xml.readElementText().toAscii()));
        	 qDebug() << " ::::::::::: country_name----> ::::::::: "+xml.name().toString()+" ====== --->"+aux;

        	 m_temperature=aux;
        	 emit temperatureChanged();


         }
         if (xml.name() == "description"  )
         {

        	  m_succeeded = true;
        	        	        m_error.clear();
         QString aux111(QString::fromUtf8(xml.readElementText().toAscii()));
        m_description=aux111;
        	 emit descriptionChanged();
         }
      }
      }
    if (!responseValue.isValid()) {
        m_error = tr("Query failed: invalid return value");
        emit statusChanged();

        m_active = false;
        emit activeChanged();

        emit complete();
        return;
    }

    if (QString::compare("true", responseValue["Success"].toString(), Qt::CaseInsensitive) == 0) {
        m_succeeded = true;
        m_error.clear();

        emit temperatureChanged();
        emit descriptionChanged();
    } else {
        m_succeeded = false;
        m_error = responseValue["item"].toString();
    }

    emit statusChanged();

    m_active = false;
    emit activeChanged();

    emit complete();
}

 can anybody let me know, what to do next ?

how to save data in groupdata model

 

BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: parsing xml into groupdatamodel and displaying in listview

Hi,

 

You are already saving the data to the datamodel using the following statement:

 

// Add the data to the model
pModel->insertList(list.value<QVariantList>());

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Regular Contributor
umairqureshi_6
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: parsing xml into groupdatamodel and displaying in listview

how to check data is inserted in groupdatamodel

 

secondly, i have defined a group data model in my qml, how to integrate with that ?

BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: parsing xml into groupdatamodel and displaying in listview

[ Edited ]

You can listen to the onItemAdded signal in QML to get notified when items are added to your data model.

 

And, to integrate to the data model defined in QML, it is best recommeded to use the controller/view technique. You define a C++ controller for each QML view. You can then assign values of the properties of the QML components to properties from C++. For a sample app that shows the View/Controller technique with data models, you can checkout this link on Github.

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker