Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] How to add a phone number to an existing contact with javascript ?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to add a phone number to an existing contact with javascript ?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barmeier
    wrote on 18 Feb 2012, 15:32 last edited by
    #1

    Hi,

    I wonder how I can add a phone number to an existing contact ? Are there any Code snippets available ?

    Thanks.

    Bye
    Matsimoto

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on 18 Feb 2012, 18:44 last edited by
      #2

      Hi,

      I wrote this using "this example":http://doc.qt.nokia.com/qtmobility/qml-contacts.html#contact-element

      @
      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 :)

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • B Offline
        B Offline
        barmeier
        wrote on 18 Feb 2012, 18:54 last edited by
        #3

        Hi,

        OK thanks a lot.
        Your post clarified many other things too.

        Ciao
        Matsimoto

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on 18 Feb 2012, 19:13 last edited by
          #4

          Nice to hear this :)

          May be I should add this code as snippet in the Wiki.

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • B Offline
            B Offline
            barmeier
            wrote on 18 Feb 2012, 19:28 last edited by
            #5

            Jepp, I think the main thing that a someone new to QML/Javascript/QT is that this Qt.createQmlObject command is the way to create the QML Objects needed.

            1 Reply Last reply
            0

            1/5

            18 Feb 2012, 15:32

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved