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 contact with javascript ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to add a contact with javascript ?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.5k 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 last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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);
      }
      @

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        barmeier
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

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