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 Contributor
Posts: 2
Registered: ‎01-09-2013
My Device: Bold 9900
My Carrier: Rogers
Accepted Solution

How can I access a qml component in C++ from a page was generated dynamically?

Hi,

 

I'm new to QML and Cascades development and I have the following scenario. On my main page, I have a ListView and when a list item is pressed, a new page is created dynamically and pushed onto the navigation stack. I am able to see the new page, but it is blank. The qml code for this new page is defined in a separate file called DirectionViewer.qml. To achieve this, in my main.qml file I have the following snippet of code:

 

attachedObjects: [
                ComponentDefinition {
                    id: directionViewer
                    source: "DirectionViewer.qml"
                }
            ]

 

In DirectionViewer.qml, I created another list view and have given it an objectName called directionList. My question is, how can I access "directionList" in C++, such that I can set the dataModel of the list from my C++ code?

 

Thanks.

Developer
Posts: 97
Registered: ‎07-17-2008
My Device: Not Specified

Re: How can I access a qml component in C++ from a page was generated dynamically?

Youe should use following code in c++ file:

    // Retrieve the list so we can set the data model on it once
    // we retrieve it
    mListView = root->findChild<ListView*>("list");
 
Hope this helps.
 
 
Thanks and regards,
Shubhangi
Developer
Posts: 217
Registered: ‎09-18-2009
My Device: Z10
My Carrier: O2

Re: How can I access a qml component in C++ from a page was generated dynamically?

Write a method in C++ and pass your ListView.

 

void ListViewUtil::setDataModel(QObject* listViewObject)

 In C++ you can cast the QObject to ListView.

ListView listView = dynamic_cast<ListView *>(listViewObject);

 Then set the data model.

New Contributor
Posts: 2
Registered: ‎01-09-2013
My Device: Bold 9900
My Carrier: Rogers

Re: How can I access a qml component in C++ from a page was generated dynamically?

Thanks for replies! I appreciate it. I managed to figure it out Smiley Happy

Developer
Developer
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: How can I access a qml component in C++ from a page was generated dynamically?

please mark the thread as solved. 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com