09-07-2012 04:35 PM - edited 09-07-2012 04:36 PM
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?
Solved! Go to Solution.
09-08-2012 02:52 AM
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.
09-10-2012 06:16 PM - edited 09-10-2012 06:22 PM
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... ![]()
09-11-2012 01:31 AM
Hi,
please check this link may be helps you.
09-11-2012 05:14 PM
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! :-)
09-18-2012 12:21 AM
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();
09-18-2012 02:01 PM
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. ![]()
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. ![]()