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: 296
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -
Accepted Solution

Update a in C++ created GroupDataModel after the Cascades UI is loaded

[ Edited ]

I created a simple GroupDataModel in my C++ code and show it inside my Cascades UI. After once it is displayed it seems I'm unable to change the content of my GroupDataModel. If I still try it the UI freezes. In the debugmode I get this error:

An internal error has occurred.
java.util.concurrent.RejectedExecutionException

 

Here are the relevant parts of my testing code:

 

.h

bb::cascades::GroupDataModel *modelRandom;
QVariantMap map;

 .cpp

QmlDocument *qml = QmlDocument::create("main.qml");
qml->setContextProperty("logic", this);
GroupDataModel *modelRandom = new GroupDataModel(
QStringList() << "ID" << "Text" );
map["ID"] = "6";
map["Text"] = "textitem";
modelRandom->insert(map);
map["ID"] = "2";
map["Text"] = "textitem2";
modelRandom->insert(map);
qml->setContextProperty("modelRandom", modelRandom);
AbstractPane *root = qml->createRootNode<AbstractPane>();
Application::setScene(root);

 

.qml

ListView {
	id: listView        
	dataModel: modelRandom
	listItemComponents: [    
		ListItemComponent {
			type: "listItem"      
			StandardListItem {
				title: ListItemData.Text
				}
			}
		]
		function itemType(data, indexPath) {
			if (indexPath.length == 1) {             
				return "header";
			} else {               
				return "listItem";
			}
		}
	} 
}

 

 

As soon as I call this later in a different function the UI freeze:

		
map["ID"] = "4";
map["Text"] = "textitem3";
modelRandom->insert(map);

 Has anyone a Idea?

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded

It doesnt seem like your whole block of code is here. It looks like you are inserting the same map object 2x into your data model, any reason why you are doing that?

 

I would also instead of setting a context property on the QmlDocument, just find a reference to the ListView via root->findChild("listobjectname") and then set the data model directly on the listview instead of through the property.

 

Then if you want to update it, grab the listview again from the scene and then update the data model.

Like all of my posts
Developer
Posts: 296
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded

[ Edited ]

kylefowler wrote:

It doesnt seem like your whole block of code is here. It looks like you are inserting the same map object 2x into your data model, any reason why you are doing that?

 


It was simply for testing and only text. I posted only the code I thought it is needed to explain what doesn't work over here to keep my post as short as possible.

 


kylefowler wrote:

I would also instead of setting a context property on the QmlDocument, just find a reference to the ListView via root->findChild("listobjectname") and then set the data model directly on the listview instead of through the property.

 

Then if you want to update it, grab the listview again from the scene and then update the data model.


Thanks, currently trying with slow progress. Using it via context property seemed a lot more easier to me.

 

And the reason why my app is freezing is not the GroupDataModel, it is because I'm calling a C++ function from my qml code. It seems I doing it totally wrong. Currently very frustrating... :smileysad:

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

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded

Developer
Posts: 296
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded

Ah, thanks. I finally got it working.

 

Setting the model via context property was perhaps not the idea. It worked just fine at MeeGo-Harmattan. I created also some other issues while searching for the reason why my code wasn't working, so I'm sadly unable to point to a specific problem my code had.

 

But the stuff from your link worked just fine und after loading the root and Listview element in the same way and adopting the qml file it just began to work. A very good example.

 

Thanks a lot! :-)

Developer
Posts: 175
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded

Is this a bug? I'm facing same problem where I clear my data model in C++ then load it with new data and the UI just freezes. I don't understand why I need to search for ListView element in QML from C++, load the data model from it and then setting it back. 

 

I would think thats inefficient and by just changing the datamodel in C++ the QML would refresh?

 

After all QML updates when I call myGroupDataModel->clear(); 

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Posts: 296
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: Update a in C++ created GroupDataModel after the Cascades UI is loaded


Produktyf wrote:

Is this a bug? I'm facing same problem where I clear my data model in C++ then load it with new data and the UI just freezes. I don't understand why I need to search for ListView element in QML from C++, load the data model from it and then setting it back. 

 

I would think thats inefficient and by just changing the datamodel in C++ the QML would refresh?

 

After all QML updates when I call myGroupDataModel->clear(); 


It feels like a bug, yes. At pure qml (MeeGo, maemo and Symbian) I was able to provide the model as a property and update it later from within my C++ code without problems. But Cascades seems to work different.

 

 

We are at cascades also at other places forced to do UI stuff in C++ and mix interface and logic. At example the ActivityIndicator.

 

At MeeGo I'm normaly able to provide a boolean to my qml model like this:

ActivityIndicator {
    running: Logic.blnWaiting
}

If the blnWaiting value is true the ActivityIndicator is visible and running. If it is false it is deactivated.

 

But at Cascades there is nothing like a running or active property. At least I haven't found one. So I'm forced to create a *mActivityIndicator Object in my C++ code and set the Indicator via ->start(); and ->stop();

 

It works just great after realizing how it should work. But it still feels not correct to me. :smileysad:

 

So I'm not sure if this behavior above is intended or a bug. Freezing UI without error message is in my opinion never a sign of stable working code. So lets see what the next Beta Release will deliver. :smileywink: