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
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

How to stored data into key value pair format?

Hi All,

 

I want to store data in key value pair format for that i'm using QVariantMap and converting into QVariant. Below is my code. But is showing blank.

	QVariantMap *syncLead_Value=new QVariantMap();
	syncLead_Value->insert("eventId", eventId);
	syncLead_Value->insert("UserId", userId);
	syncLead_Value->insert("BarcodeID", barcodeId);
	syncLead_Value->insert("Phone", phone);
	syncLead_Value->insert("state", state);
	syncLead_Value->insert("LastName", lName);
	syncLead_Value->insert("FirstName", fName);
	syncLead_Value->insert("City", city);
	syncLead_Value->insert("Email", emailId);
	syncLead_Value->insert("Notes", notes);
	syncLead_Value->insert("ScannedTime", scannedTime);
	syncLead_Value->insert("Designation", title);
	syncLead_Value->insert("NextFollowUpdate", nextFollowUpdate);
	syncLead_Value->insert("Company", compName);
	syncLead_Value->insert("leadRating", rating);
	syncLead_Value->insert("RecordId", recordId);
	syncLead_Value->insert("FollowupTypes", followUpTypes);
	syncLead_Value->insert("SurveyAnswer1", surveyAnswer1);
	syncLead_Value->insert("SurveyAnswer2", surveyAnswer2);
	syncLead_Value->insert("SurveyAnswer3", surveyAnswer3);


	QVariant stream = syncLead_Value->values();
qDebug()<< "Body part data" << stream.toString();

 Actually i have to pass data into JSONArray format using HttpConnection bcz my web service does supports only JsonArray data into body. Pls help me to acheive the same.

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to stored data into key value pair format?

[ Edited ]

stream should be a QVariantList, not just a single QVariant.



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to stored data into key value pair format?

Thanks for reply, can u tell me how to convert QVariantMap into QVariantList?

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

Re: How to stored data into key value pair format?

Actually what i want to do is, stored data into key value pair and convert then into byte array,bcz post method of http connection will takes only byte array value.
Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to stored data into key value pair format?

For your first question:

QVariantList stream = syncLead_Value->values();

 As for your second question, you're probably best using JsonDataAccess saveToBuffer to convert your map into JSON data to transmit.



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to stored data into key value pair format?

as per ur second answer same i did but now problem is need to convert JsonDataAccess into QByteArray format bcz post method support only QByteArray parameter.
Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to stored data into key value pair format?

You don't need to convert JsonDataAccess into anything. It's just a tool. Try this:

 

JsonDataAccess jda;
QByteArray* buffer = new QByteArray();
jda.saveToBuffer(syncLead_Value, buffer);

 The contents of your map should now be in buffer, ready to send.



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to stored data into key value pair format?

Hi,

Thanks for code, but saveToBuffer method has takes only QVariant parameter.

and one more thing then how to pass 'jda' in my http connection body.

Developer
Posts: 75
Registered: ‎09-12-2012
My Device: Looking for a BB10 testing device
My Carrier: Developper

Re: How to stored data into key value pair format?

Hi, why don't you use QSettings ? http://developer.blackberry.com/cascades/reference/qsettings.html

---------
Mobile developer freelance - QtQuick - Cascades - WP7 - Android
My works : http://fdelgado.fr
Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to stored data into key value pair format?

QSettings only works for storing preference data locally, it can't be used for creating a QByteArray to transmit.

 

QVariantMap is also a child class of QVariant, so you should be able to pass syncLead_Value into jda directly. And you don't pass jda into your HTTP connection body, you pass buffer from my code above.



Did this post help you? If so, please make sure to "like" it!