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: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Retrieve Value Back from QVariantMap

Hi everyone,

 

In my application, I have to place a bb::cascades::Image object to a QVariantMap. Like the code below (simplified)

 

    QVariantMap map;

    Image *image = new Image[4];

    image[0] = Image(data);
    map["imageData"]=QVariant::fromValue(image[0]);

    image[1] = Image(data);
    map["imageData"]=QVariant::fromValue(image[1]);

    image[2] = Image(data);
    map["imageData"]=QVariant::fromValue(image[2]);

    image[3] = Image(data);
    map["imageData"]=QVariant::fromValue(image[3]);

 

And at other point of my app, I would like to retrieve the value I stored into the QVariantMap back to bb::cascades::Image.

 

Any suggestions on how to do this please ?

 

Thanksss

 

jayvdiyk.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Retrieve Value Back from QVariantMap

Hi! Something like this should work if ImageData is registered as a metatype (I don't know if it is):

 

ImageData *imageData = QVariant::value<ImageData *>();
Image *img = new Image(*imageData);
delete imageData; // no longer needed

 Otherwise the code will be a bit more complex, please tell if the above code won't work.

 


Andrey Fidrya, @zmeyc on twitter
Highlighted
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Retrieve Value Back from QVariantMap

[ Edited ]

Hi Zmey,

Thanks for the reply.

I just realized that the code I wrote isn't complete. I forgot to include the arrayDataModel.

What I meant to ask was, I put all those QVariantMaps into a arrayDataModel. How do I retrieve them back based on the index I selected from the listView.

Sorry for the confusing question

QVariantMap map;

Image *image = new Image[4];

image[0] = Image(data);

map["imageData"]=QVariant::fromValue(image[0]);
arrayDataModel->append(map);


image[1] = Image(data);

map["imageData"]=QVariant::fromValue(image[1]);
arrayDataModel->append(map);


image[2] = Image(data);

map["imageData"]=QVariant::fromValue(image[2]);

arrayDataModel->append(map);


image[3] = Image(data);

map["imageData"]=QVariant::fromValue(image[3]);
arrayDataModel->append(map);

listView->setDataModel(arrayDataModel);
 

jayvdiyk.com