Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129972

[REG 6.6 → 6.7] Array returned to QML from CPP is not retaining changes made in QML/JS

    XMLWordPrintable

Details

    • All
    • cca0b460f (dev)

    Description

      The array (QVariantList) returned from C++ to QML is not reflecting the changes made in QML/JS when we attempt to assign a new value to an item.

      • We have an array of objects returned from C++, and when we assign a new value to an item in that array, the item's value does not update at all, remaining as the original value instead.

      C++:

      QVariantList Contacts::getContacts() const {
          return QVariantList {
              QVariantMap { {"name", "Alice Smith"}, {"email", "alice@example.com"}, {"phone", "123-456-7890"} },
              QVariantMap { {"name", "Bob Johnson"}, {"email", "bob@example.com"}, {"phone", "987-654-3210"} },
              QVariantMap { {"name", "Charlie Brown"}, {"email", "charlie@example.com"}, {"phone", "555-555-5555"} }
          };
      } 

      QML:

      Window {
          width: 640; height: 480
          visible: true
          Contacts { id: contactsModel }
          Component.onCompleted:{
              const items = contactsModel.getContacts()
              console.log("Original List", JSON.stringify(items))
              console.log("Before item 1 modified", JSON.stringify(items[0]))
      
              items[0].email = "This Email Should Mutate"
      
              console.log("After item 1 modified", JSON.stringify(items[0]))
          }
      } 

      Output log:

      Original List [{"email":"alice@example.com","name":"Alice Smith","phone":"123-456-7890"},{"email":"bob@example.com","name":"Bob Johnson","phone":"987-654-3210"},{"email":"charlie@example.com","name":"Charlie Brown","phone":"555-555-5555"}]
      Before item 1 modified {"email":"alice@example.com","name":"Alice Smith","phone":"123-456-7890"}
      After item 1 modified {"email":"alice@example.com","name":"Alice Smith","phone":"123-456-7890"} 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            diseraluca Luca Di Sera
            sunilfyi Sunil Reddy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes