[SOLVED] How to add a contact with javascript ?
-
Hi,
after several hints I got in ths forum I was able to retrieve and change contact entries.
But how can I add a contact using javascript in a JS-File ?I started this very naiv try:
@ var contact = {
name : {
lastName: "Pusel",
firstName: "Peter"
}
};myContactModel.saveContact(contact);
@
This doesn't produces an error but it does not work either.
Any hints ?
Ciao
Matze -
ContactModel.saveContact() takes in a qml Contact element. So, passing a standard JS var is not enough.
Try:
@
var component = Qt.createComponent("Contact"); // or, use Qt.createQmlObject()
var contact;if (component.status == Component.Ready) {
contact = component.createObject(parent);
}
@ -
Hi,
thanks for your reply. This was the right hint!
I needed some further investigation to make it work but now it works as expected.Just for other who may have the same problems this code solved my problem:
@ var contact = Qt.createQmlObject("import QtMobility.contacts 1.1; Contact {id: myContact; Name { firstName:'John'; lastName:'Gates' } }",parent);
this.localContacts.saveContact(contact);@Ciao
Matze