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
lazior
Posts: 18
Registered: ‎01-18-2013
My Device: Z10 10.2
Accepted Solution

Dynamic Drop Down with database

Hello everyone,

 

I want to create a dynamic dropdown and use the database as its option.

 

I have a navigationPane main.qml with a add action:

 

NavigationPane {
    id: navigationPane
    .....
    actions: [ 
        ActionItem {
            title: qsTr("add")
            ......

            onTriggered: {
                navigationPane.push(edit.createObject());
            }
        }
    ]
    attachedObjects: [
        ComponentDefinition {
            id: edit
            source: "edit.qml"
        }
    ]
    .....
}

And edit.qml contain the dropdown component:

 

Page {
.....
DropDown {
id:dropdown
.......
}
}

 

Then how can I get the dropdown in the app.cpp ?

 

I known if the dropdown is it the main.qml

Then I can get the dropdown easily by using this

 

In app.cpp

App::App() {
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    qml->setContextProperty("_app", this);

    AbstractPane *root = qml->createRootObject<AbstractPane>();

    Application::instance()->setScene(root);

    dropDown = root->findChild<DropDown*>("editDropDown");

    while(still have data)
        dropDown->add(Option::create().text(data).value(1));
}

 

But I don't know how to do it if the dropdown component is in the other QML file.

 

Can anybody help me...?

 

And thanks for my poor English....

 

Thank a lot!!

Developer
ekke
Posts: 1,561
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Dynamic Drop Down with database

if your DropDown has a unique ObjectName and the Page is created and pushed,

then findChild will find it

 

if there are more then on DropDown with the same objectname

findChildren gives you the list

 

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

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
lazior
Posts: 18
Registered: ‎01-18-2013
My Device: Z10 10.2

Re: Dynamic Drop Down with database

[ Edited ]

Thanks ekke for your useful reply.

 

My DropDown has a unique ObjectName Name "editDropDown"

And it it in the edit.qml file.

 

But I will create main.qml first

then cteate and navigate to the edit.qml 

 

Since when I open my app, 

the main.qml and app.cpp is created, but edit.qml haven't.

And if I point to the dropdown in the edit.qml ,

the app will crash.....

 

My Question is how to first create edit.qml in the app.cpp?

Is my thought wrong?

 

 ------- edit ------

 

OH!!
I know it !

I can create the dropdown in the app.cpp

after navigation(edit.createObject())

and it work for me!!

 

Thanks again!

Developer
ekke
Posts: 1,561
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Dynamic Drop Down with database


lazior wrote:

Thanks ekke for your useful reply.

...

 

 ------- edit ------

 

OH!!
I know it !

I can create the dropdown in the app.cpp

after navigation(edit.createObject())

and it work for me!!

 

Thanks again!


thats the way I'm doing such kind of stuff:

create the component

then - before pushing the page on top - calling cpp to fill DropDown with values from database

 

great to hear that it works for you

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

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner