[Solved] How to add a phone number to an existing contact with javascript ?
Hi,
I wonder how I can add a phone number to an existing contact ? Are there any Code snippets available ?
Thanks.
Bye
Matsimoto
4 replies
Hi,
I wrote this using this example [doc.qt.nokia.com]
- Rectangle {
- id: topItem
- width: 360
- height: 640
- x: 0
- y: 0
- Contact {
- id: myContact
- Name {
- firstName:"John"
- lastName:"Gates"
- }
- EmailAddress {
- emailAddress:"john@example.com"
- }
- EmailAddress {
- emailAddress:"mygmailaccount@gmail.com"
- }
- address.street:"53 Mysteet St"
- address.locality: "My City"
- address.region: "My Region"
- address.postcode:"1111"
- address.country:"My Country"
- address.subTypes:[Address.Postal, Address.Domestic]
- address.postOfficeBox:"1111"
- Nickname {
- nickname:"John"
- }
- PhoneNumber {
- number: "1111111111"
- subTypes:[PhoneNumber.Mobile]
- }
- PhoneNumber {
- number: "2222222222"
- subTypes:[PhoneNumber.Fax]
- }
- PhoneNumber {
- number: "3333333333"
- subTypes:[PhoneNumber.Landline]
- }
- Component.onCompleted: {
- // create new phone number
- var newNumber = Qt.createQmlObject('import QtMobility.contacts 1.1; PhoneNumber { number: "1234567890" }',
- myContact, "newNumber");
- myContact.addDetail( newNumber )
- myContact.save();
- for( var i = 0; i < myContact.phoneNumbers.length; ++i ) {
- console.debug( "Phone number: " + myContact.phoneNumbers[i].number )
- }
- }
- }
- Column {
- spacing:4
- //access the same property with different syntaxes
- Text { text:"Name(from property name):" + myContact.name.firstName + " " + myContact.name.lastName }
- Text { text:"Name(from detail type):" + myContact.detail(ContactDetail.Name).firstName + " " + myContact.name.lastName }
- Text { text:"Name(from detail name):" + myContact.detail("Name").firstName + " " + myContact.name.lastName }
- Text { text:"Address:" + myContact.address.street + " " + myContact.address.locality + " " + myContact.address.region + " " + myContact.address.postcode }
- //If a contact contains multiple details for the same detail type, you can access them with the dynamic property names.
- Text { text:"How many email accounts?:" + myContact.emails.length }
- Text { text:"Email[0]:" + myContact.emails[0].emailAddress }
- Text { text:"How many phone numbers?:" + myContact.phoneNumbers.length }
- Text { text:"phone number[0]:" + myContact.phoneNumbers[0].number }
- Text { text:"phone number[1]:" + myContact.phoneNumbers[1].number }
- Text { text:"phone number[2]:" + myContact.phoneNumbers[2].number }
- }
- }
See Component.onCompleted . It should work everywhere you can access contancts from ContactManager.
I hope this will be usefull for you :)
You must log in to post a reply. Not a member yet? Register here!
