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
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom
Accepted Solution

findChild custom datamodel

Hello,

I know how to retrieve a QML object from C++. For instance, if myObj is a TextArea, I can change the text like this :

 

QObject *obj = appPage->findChild<QObject*>("myObj");  
if (myObj){
	myObj->setProperty("text", "hello");
}

 Now, I would like to get the DataModel of a ListView, which one is a custon DataModel :

 

ListView {
    dataModel: searchModel
...
}

attachedObjects: [
       
	SearchModel {
		id: searchModel
		jsonAssetPath: "app/native/assets/appsearch.json"
		filter: "All categories"
	}
]	

 

At least, my SearchModel has a public slot : void updateListWebviews(const QString text);

I would like to trigger the updateListWebviews slot in a cpp function. Could you help me to achieve this please ?

 

Thanks for your help,

Laurent

Twitter : @LaurentKP
My apps
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: findChild custom datamodel

give it an objectname and it should be obtainable with findChild.
----------------------------------------------------------
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
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: findChild custom datamodel

[ Edited ]

Something like that :

ListView* webWiewsList = appPage->findChild("webWiewsList");

SearchModel* mySearchModel = webWiewsList.dataModel;

mySearchModel.updateListWebviews(m_data);

 

Or maybe :

SearchModel* mySearchModel = appPage->findChild("searchModel");

mySearchModel.updateListWebviews(m_data);

Twitter : @LaurentKP
My apps
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: findChild custom datamodel

You can also do it from the other direction by giving an object to QML with some kind of "setDataSource" method. Then you call that from javascript with the data model you want to pass to C++. Or create the datasource in C++ in the first place.

 

This makes it easier to keep the UI and appliation logic separate, and can be faster than using findChild (though it's fine once in a while)

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: findChild custom datamodel

Actually I need to do it from C++ because I'm working in the signal when my app is invoked by another. ListView* webWiewsList = appPage->findChild("webWiewsList"); or SearchModel* mySearchModel = appPage->findChild("searchModel"); does not work because ListView and SearchModel are qml object type not QT Objects. May be I could call a javascript function from C++ ????
Twitter : @LaurentKP
My apps
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: findChild custom datamodel

you can access the "qml objects" just fine, behind the scenes they are ordinary c++ objects.

you can invoke a qml method using QMetaObject::invokeMethod

you can also connect a c++ signal in qml and just emit the signal to your UI. I would deem that the most elegant solution.
----------------------------------------------------------
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
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: findChild custom datamodel

You're right Simon. SearchModel *mySearchDataModel = Application::instance()->scene()->findChild("searchModel"); works well. thank you, Laurent
Twitter : @LaurentKP
My apps