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: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT
Accepted Solution

Dynamically populate QML DropDown (within Sheet) from C++

Hi all,

 

I've got an issue where I'm trying to set the contents of a dropdown from C++.

 

I won't put the ful QML layout as it is fairly substantial, but this is the overall structure:

 

NavigationPane>Page>(Attached Objects)Sheet>ContentSmiley Tongueage>Container>ScrollView>Container>DropDown (objectName: ddType)

 

In my C++, I have the following code:

 

Header file:

DropDown *ddType;

 

CPP file:

ddType = navigationPane->findChild<DropDown*>("ddType");

ddType->add(Option::create().text("Option 1"));

 

When I debug, I get a "No source available for "bb::cascades:Smiley Very HappyropDown::add() at 0x78620bac" error on the ddType->add line, and the app exits completely.

 

I've used navigationPane->setProperty() successfully for other purposes, so it seems I can access the navigationPane OK.

 

Is there a limitation with findChild on attached sub components (e.g. sheets?)

 

Any ideas?

Developer
Posts: 1,163
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Dynamically populate QML DropDown (within Sheet) from C++

[ Edited ]

First off... please post code with the code button in the editor to avoid having all kinds of smiley faces in your post when you use colons.

 

Now to your question... I have not used findChild(), but I'd be willing to bet the "name" it searches for is not the "id:" value, but the "objectName:" setting instead. 

 

Did you define objectName: on your QML DropDown?

 

Also, it is always good practice to test the return value of a function like findChild() to ensure the result is valid before you use it.


Royster86 wrote:

Hi all,

 

I've got an issue where I'm trying to set the contents of a dropdown from C++.

 

I won't put the ful QML layout as it is fairly substantial, but this is the overall structure:

 

NavigationPane>Page>(Attached Objects)Sheet>ContentSmiley Tongueage>Container>ScrollView>Container>DropDown (objectName: ddType)

 

In my C++, I have the following code:

 

Header file:

DropDown *ddType;

 

CPP file:

ddType = navigationPane->findChild<DropDown*>("ddType");

ddType->add(Option::create().text("Option 1"));

 

When I debug, I get a "No source available for "bb::cascades:Smiley Very HappyropDown::add() at 0x78620bac" error on the ddType->add line, and the app exits completely.

 

I've used navigationPane->setProperty() successfully for other purposes, so it seems I can access the navigationPane OK.

 

Is there a limitation with findChild on attached sub components (e.g. sheets?)

 

Any ideas?


 

AppSettings::



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Dynamically populate QML DropDown (within Sheet) from C++

Hi,

 

Thanks - yes, I define the objectName within the DropDown object in the QML:

 

Container {
DropDown {
    id: ddType
    objectName: ddType
}
...
}

 I have updated as you suggested to check the return value, but it always fails:

 

ddType = navigationPane->findChild<DropDown*>("ddType");
	
if(ddType)
ddType->add(Option::create().text("Option 1"));

 Interesingly, I also tried to see what properties are available using intellisense, however, when I type ddlType-> I get no suggestions.

 

When I do the same thing with a GroupDataModel I get the intellisense suggestions as you'd expect:

mDataModel = navigationPane->findChild<GroupDataModel*>("listDataModel");
mDataModel-> (intellisense appears)

 

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Dynamically populate QML DropDown (within Sheet) from C++

objectname needs to be in quotes.


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: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Dynamically populate QML DropDown (within Sheet) from C++

Absolutely brilliant - can't believe I've wasted so much time on that!!!

Thanks very much!