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
New Developer
georg
Posts: 86
Registered: ‎01-23-2009
My Device: Z10

Access components in attached objects

I have a dialog as attached object in my page. My interaction with it is just my_dialog.open() on some events but I'm asking me if it would be possible to access its components (in this case some text fields) to modify their content.

 

The dialog has a structure like:

Dialog{

  Container {

    Container {

       TextField {
          id: text_field_one

 

something like my_dialog.text_field_one.text = ... however does not work.

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Access components in attached objects

if you access it in the same qml you should be able to modify the textfield by its id only, like "text_field_one.text ="
otherwise you should define a property for it.
----------------------------------------------------------
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
New Developer
georg
Posts: 86
Registered: ‎01-23-2009
My Device: Z10

Re: Access components in attached objects

My dialog does indeed reside in a separate file. How do I defina a property for it?

Developer
bbdevguy
Posts: 107
Registered: ‎11-19-2008
My Device: Not Specified

Re: Access components in attached objects

You can do that via the objectName property.

 

attachedObjects:[

Dialog{

  objectName: "mydialog"

  Container {

    Container {

       TextField {
          id: text_field_one

          objectName:"mytextfield"

...

 

Then from C++ use

 

Dialog* mydialog = root->findChild<Dialog*>("mydialog");
TextField* mytextfield = mydialog->findChild<TextField*>("mytextfield");

 

 

This also works for attached object defined in their own QML file.