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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 251
Registered: ‎11-22-2011
My Device: Blackberry Playbook
My Carrier: vodafone
Accepted Solution

Remove dynamic created component with QML?

Hi,

 

how can i store the reference of the created object, for example to remove it later.

In the example below the reference "createdControl" is stored in a local variable of the "onClicked" handler and is not accessable later. 

Its not possible to use a property of the Container to store it, because then i need to specify a datatype ( strangely enough its possible to store it in an imported javascript file in a typless variable....). 

 

So this reference seems to be pretty useless for now, or am i missing something?

 

Thanks.

 

Container {              
    id: rootContainer               
    Label  {                  
        text: "Example Component Definition"              
    }              
    Button  {                  
        text: "Click to create dynamic component"
        onClicked :  {                      
            // Create the component and add it to the Container   
            var createdControl = compDef.createObject();
            rootContainer.add(createdControl);
        }             
    }
    attachedObjects: [                  
        ComponentDefinition {                      
            id: compDef                       
            source: "test.qml"             
        }
    ]         
}

 

Developer
Posts: 251
Registered: ‎11-22-2011
My Device: Blackberry Playbook
My Carrier: vodafone

Re: Remove dynamic created component with QML?

Ok, the right datatype is "variant", sorry, i searched for an hour, just found it 

Regular Visitor
Posts: 1
Registered: ‎10-19-2012
My Device: BB10
My Carrier: Telus

Re: Remove dynamic created component with QML?

Hey, I'm doing pretty much the same thing, COuld you elaborate on how you solved this, I'm having some trouble still.

 

Thanks

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Remove dynamic created component with QML?

something like this should fix it:

 

Container {              

property variant createdControl;

    id: rootContainer               
    Label  {                  
        text: "Example Component Definition"              
    }              
    Button  {                  
        text: "Click to create dynamic component"
        onClicked :  {                      
            // Create the component and add it to the Container   
            var createdControl = compDef.createObject();
if(!createdControl) createdControl = compDef.createObject(); rootContainer.add(createdControl); } } attachedObjects: [ ComponentDefinition { id: compDef source: "test.qml" } ] }

 

Highlighted
New Developer
Posts: 41
Registered: ‎02-11-2010
My Device: Bold 9000
My Carrier: AT&T

Re: Remove dynamic created component with QML?

OK so how do i call the function to remove. is it destroy or remove...neither of those are working for me.. could you help me with an example?
Developer
Posts: 1,750
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV, DTEK
My Carrier: Telekom.de, O2, Vodafone

Re: Remove dynamic created component with QML?

I also didn't found a way to destroy dynamically created objects

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
QtChampion
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS, W10)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Remove dynamic created component with QML?

to remove:

https://developer.blackberry.com/cascades/reference/bb__cascades__container.html#remove

 

to delete a qml object, use:

destroy()

 

NOTE:

1) when deleting qml objects, it is not garanteed to be freed immediately

2) QML cleans objects automatically within some sort of GC using the parent-child relationship of all the QML objects...so you don't have to clean you dynamically created elements unless you removed it from its parent or its parent won't be deleted until the app is closed

3) to add to pt (2), destroying a parent object also destroys all its childs.

4) destroy are often used in a NavigationPane or TabbedPane....if you have many different Pages or Tabs, you might want to destroy them when it is no longer active, else they won't be cleaned up until the NavigationPane or Tabbedpane is destroyed (for some cases, it could be when the app exits...and that's not good)

5) play around with the above while monitoring the heap usage using the QNX System Information Perspective!

 

hope this helps!

Developer
Posts: 1,750
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV, DTEK
My Carrier: Telekom.de, O2, Vodafone

Re: Remove dynamic created component with QML?

thx lew Smiley Happy

 

now it works

 

I had to use my custom QML Type: (UsersNavPane)

TabbedPane {
    property UsersNavPane n;  

 then to create the dynamic object this way

function createUserTabComponent() {
    n = onDemandComponentUsersNavPane.createObject();
    usersTab.content = n;

 and destroying works this way

function destroyUserTabComponent() {
    if (usersTab.content) {
        usersTab.resetContent();
        n.destroy()
    }

 

thx

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
QtChampion
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS, W10)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner