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
raj_jyani
Posts: 107
Registered: ‎05-11-2011
My Device: BlackBerry Z10 LE

Dynamically add control

Hi ,

 

i want to add controls dynamically to container . but when i call Q_INVOKABLE method with name getLikesList() from qml my application crashe. If i call method from button click it's working but call method from onCreationCompleted crash application. i want to call method automatically not on button click event.

 

anyone know where should i write app.getLikesList() statement.

 

My qml

import bb.cascades 1.0

Page {
    content: Container {
        objectName: "containerLikes"
        Button {
            text: "Button"
            onClicked: {
                //app.getLikesList()
            }
        }
    }
    onCreationCompleted: {
        app.getLikesList()
    }
}

 Cpp

void App::getLikesList() {
// find method can not find containerLikes object when call from onCreationCompleted
	Container *container = root->findChild<Container*>("containerLikes"); 
	activityIndicator = ActivityIndicator::create();
	activityIndicator->start();
	container->add(activityIndicator);
}

 

is any way to dynamically add controls from qml file ?

 

 

Thank You

 

BlackBerry Development Advisor (Retired)
amarcon
Posts: 155
Registered: ‎07-16-2012
My Device: Dev Alpha

Re: Dynamically add control

Developer
raj_jyani
Posts: 107
Registered: ‎05-11-2011
My Device: BlackBerry Z10 LE

Re: Dynamically add control

Hi amarcon,

 

Thank you for your reply, but my problem is 

Container *container = root->findChild<Container*>("containerLikes");

cannot find container object from qml when i used  

onCreationCompleted: {
        app.getLikesList()
 }

 

if i call app.getLikesList() from button click event then it completely working .

 

is any statement like we use in java invokeLater() ?

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Dynamically add control

Hi raj_jyani,

 

We are also adding dynamic controls to my Page. You can have two approaches here - 

 

1.) Either, add Like List to your existing page, and keep it invisible, and at runtime when you want to show it, make it visible.

2.) Make a separate custom component for your Like List (QML Document- say it as LikeList.qml). Now, at runtime, add it to your page as 

 

void App::addLikeLits() {

 QmlDocument *qml = QmlDocument::create().load("LikeList.qml");

 if (!qml->hasErrors()) {
    Container *control= qml->createRootNode<Container>();
    if (control) {
    	myContainer->add(control);
    }
 }
}

 I am using both approaches in my app, and duo are working fine.

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
raj_jyani
Posts: 107
Registered: ‎05-11-2011
My Device: BlackBerry Z10 LE

Re: Dynamically add control

Hi Kanak.

 

Thank you for your reply, i understand your point .

 

i m getting data from web server so count is not predefined that's why i not apply visibility concept.

i think you did not mark my problem . my adding data code completely working but only on button click event.

i want to call it automatilly when page is complete render. so i called method from onCreationCompleted:

but it's not working .


i can add control from onClick event  but not from onCreationCompleted:

 

 

Thank You

BlackBerry Development Advisor (Retired)
amarcon
Posts: 155
Registered: ‎07-16-2012
My Device: Dev Alpha

Re: Dynamically add control

Hi raj_jyani,

 

now with R9, did you have a chance to take a look at this?

 

https://developer.blackberry.com/cascades/documentation/dev/dynamic_qml/index.html

 

Cheers,