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: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers
Accepted Solution

refresh a ListView when dataModel changes

Hi gang,

 

I have a GroupDataModel defined as a Q_PROPERTY of a custom C++ class.

 

i attach this GroupDataModel to a ListView in QML.

 

I make changes to the items in the GroupDataModel by pulling the items in the model into a ListOfObjects.

 

i can see that the changes are effective in by qDebug() output, but the ListView doesn't refresh.

 

on the Q_PROPERTY, i have a NOTIFY signal defined (on onItemListChanged), and in the function where i edit the items, i emit that signal (emt onItemListChanged()Smiley Wink, but the ListView doesn't do anything.

 

how can i get the ListView to update?

 

Here's the function to update the items.

 

void WorkManager::updateKey(QString newKey, int whichObject) {

	if (!newKey.isNull()) {
		QList<QObject *>  myObjects = m_model->toListOfObjects();
				Task * myTask = (Task *) myObjects[whichObject];
				qDebug() << "object is : " << myObjects[whichObject];
				qDebug() << "object key is: " << myTask->key();
				myTask->setNotifyKey(newKey);
				emit onItemListChanged();
				qDebug() << "modified object key is : " << myTask->notifyKey();
	}

}

 do i need to connect a signal to a slot somewhere?  I thought that would be done automatically.

 

thx,

 

J

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
Posts: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers

Re: refresh a ListView when dataModel changes

ah, I see. I have to actually update the model to get it to fire it's signals.

 

adding this:

 

				QVariantList indexPath = m_model->findExact(myTask);
				qDebug() << "WorkManager::updateItem(), indexPath is : " << indexPath;
				m_model->updateItem(indexPath, myTask);

 makes it work.

 

here's the full function:

 

void WorkManager::updateKey(QString newKey, int whichObject) {

	if (!newKey.isNull()) {
		QList<QObject *>  myObjects = m_model->toListOfObjects();
				Task * myTask = (Task *) myObjects[whichObject];
				qDebug() << "object is : " << myObjects[whichObject];
				qDebug() << "object key is: " << myTask->key();
				myTask->setNotifyKey(newKey);
QVariantList indexPath = m_model->findExact(myTask);
qDebug() << "indexPath is : " << indexPath;
m_model->updateItem(indexPath, myTask); qDebug() << "modified object key is : " << myTask->notifyKey(); } }
bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com