ModelContact removeContact
-
Hi,
I'm doing an application using ModelContact of QML. I get modelContact.contacts[i].contactId in an array.
So I try to delete every Contact from array.@
for(var i =0;i<JsModels.repeated.length;i++)
modelContacts.removeContact(JsModels.repeated[i])
@But it doesn't remove the contact. But if I do:
@
modelContacts.removeContact(400)
@
with a const number the function does remove.Does anybody know how I could fixe this problem?
Thanks,
Fernando Moreno. -
Presumably we're actually working with ContactModel, http://doc.qt.nokia.com/qtmobility/qml-contactmodel.html
I would say the problem here is that the values in the JsModels.repeated array are nonexistent or invalid. If I were you, I would try this:
@
for(var i =0;i<JsModels.repeated.length;i++) {
console.log("Removing contact ID " + JsModels.repeated[i])
modelContacts.removeContact(JsModels.repeated[i])
}
@
See what it's actually trying to remove. -
Hi,
thanks for reply.
Yes I did and I saw correct values. But it looks like the removeContact function don't allow this type of value. Just const int works. I think the type that I store in array is QContactId or something like that. And I cannot convert this type to const int.Best,
Fernando. -
If the console.log() line works, then obviously the array values can be interpreted as a string. If the string contains a number, we can work with that like so:
@modelContacts.removeContact(Number(JsModels.repeated[i]))@
Give that a whirl and see if it works. -
Hi,
It doesn't work yet.Thanks.
-
http://www.macieira.org/blog/2012/05/doesnt-work-doesnt-work/
Just saying... ;)I'm assuming there are no errors... I'm not entirely familiar with the Number function, so let's try parseInt instead:
@modelContacts.removeContact(parseInt(JsModels.repeated[i]), 10)@And where does JsModels come from, anyways?
-
I have to try the suggested sentece. JsModels is a "model" created by me to perform jsons using.
Best,
Fernando.