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. ModelContact removeContact
Qt 6.11 is out! See what's new in the release blog

ModelContact removeContact

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 3.2k 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.
  • K Offline
    K Offline
    kahon
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DigitalPioneer
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kahon
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DigitalPioneer
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kahon
            wrote on last edited by
            #5

            Hi,
            It doesn't work yet.

            Thanks.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DigitalPioneer
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kahon
                wrote on last edited by
                #7

                I have to try the suggested sentece. JsModels is a "model" created by me to perform jsons using.

                Best,
                Fernando.

                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