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
Highlighted
Developer
Posts: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel
Accepted Solution

how to append data into variant

Hello,

 

i have a variant into qml and i want to append some data into that variant.

 

Please suggest..


----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: how to append data into variant

[ Edited ]

QVariant data;

 

data << "1" << "2" << "3";

 

It's not possible to do this in QML you would have to assign a variant with a new value or handle it in javascript.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: how to append data into variant

BBSJdev,

i am talking about qml not c++, we can not write QVariant into qml,

 

property variant seletedimages

 

can you write the code ... 


----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: how to append data into variant

[ Edited ]

Like this for example:

for an attributes map [like JSON object]

property variant myVariant


function test(){
    var object = {}
    object.value1 = "Value1"
    object.value2 = true;
    myVariant = object
    console.debug("VALUE: ".concat(myVariant.value1))
}

for an items array

property variant myVariant


function test(){
    var array = [] // or new Array()
    array.push("value1")
    array.push("value2")
    myVariant = array
    console.debug("VALUE: ".concat(myVariant[0]))
}

 

 Hope it helps

 

EDIT:

Append is also possible

property variant myVariant: {"key1": "value1", "key2": "value2"}

function test(){
    var jsonObj = myVariant
    jsonObj.key3 = "value3";
    jsonObj.key4 = "value4";
    jsonObj.key5 = "value5";
    myVariant= jsonObj
    console.debug("VALUE: ".concat(myVariant.key4))
}

 Enjoy



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: how to append data into variant

As I've written above this is not possible, to put it another way variants are immutable the only way to change them is to change the reference however as this is very inefficient and clumsy it is best to pass to C++ or JavaScript to handle.

 

Ideally you should avoid using QML variant for data you wish to update, instead storing the data as a C++ or JavaScript variable.

 

Please close this thread off as this answers the OP and start a new one on what you are trying to achieve vis-a-vis appending data stating whether C++ or Javascript is the most suitable?

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: how to append data into variant

thanx Benacore ..

 

i have tried the way you post, but getting some problem i have number of images and onSelectionChanged inside the multiSelectAction i want to append that path(String) of the seleted image into that variant,

but only last image path is appending because every time a new copy of array is creating inside the function.

 

so its work fine only for one image.

 

Thanx Smiley Happy

 

 


----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: how to append data into variant

Please post your qml. Thanks.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: how to append data into variant

This is a different question from the first one you asked, please be clear what you want when posting a problem.

At this point I suggest posting your code for us to look at.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: how to append data into variant

[ Edited ]

Something is wrong in your code

 

This (i think ) must work 

 

property variant selectedImages: []


function appendImage(path){
    if (selectedImages.indexOf(path) === -1){ // make sure that doesn't exists
        var copy = selectedImages
        copy.push(path)
        selectedImages = copy
    }
    console.debug(selectedImages)
}


onSelectionChanged:{
    appendImage(blabla)
}

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: how to append data into variant

Great job @ Benecore

 

Smiley Happy


----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.