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: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea
Accepted Solution

dynamic dropdown

how to add options to dropdown in qml using small cpp function.....the options would be like 10 kilo,20 kilo,30kilo,40 kilo etc...

 

Please help

 

Thanks

Developer
Posts: 16,740
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: dynamic dropdown

https://developer.blackberry.com/cascades/reference/bb__cascades__dropdown.html#function-add-option
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: dynamic dropdown

im able to add options through qml...but i want to add it through my app.cpp file...

Developer
Posts: 16,740
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: dynamic dropdown

you can call this method in c++ just fine.
either create the dropdown in c++ or use findChild to get a reference to the qml object.
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: dynamic dropdown

i have created a dropdown in qml....and tryin to add options through cpp.....like this

 

DropDown* dpList = bb::cascades::Application::instance()->findChild<DropDown*>("dropdown");
dpList->add(Option::create().text("10 kilo"));
dpList->add(Option::create().text("20 kilo"));
dpList->add(Option::create().text("30 kilo"));

 

but when i run the app...i dont see any options in my dropdown

 

plz help

Developer
Posts: 16,740
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: dynamic dropdown

i suggest you add some logging to your code to see if the dropdown is successfully found and the options are added correctly.
----------------------------------------------------------
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.
@SimonHain on twitter
Developer
Posts: 19
Registered: ‎07-02-2013
My Device: BlackBerry Q10
My Carrier: Telus

Re: dynamic dropdown

Your problem here is that the DropDown is not a child of the Application. Rather it is a child of the content (main container) of the application.

So try to change your code with the following instead:

DropDown* dpList = bb::cascades::Application::instance()->scene()->findChild<DropDown*>("dropdown");

dpList->add(Option::create().text("10 kilo"));
dpList->add(Option::create().text("20 kilo"));
dpList->add(Option::create().text("30 kilo"));
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: dynamic dropdown

Thanks for the reply....but i tried that way too....still the options are not getting set to dropdown.....

 

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: dynamic dropdown

Check if dpList is null. If it is, you don' get access to the object in your qml. Di dyou assign it an objectName ?

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: dynamic dropdown

Simon and YamilBracho are right, you may not have the reference to the object.

 

For your consideration though, rather than filling a dropdown with a set of numbers, you may want to do something like a custom picker: https://developer.blackberry.com/cascades/documentation/ui/pickers/custom_pickers.html

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker