Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
6.8.0
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
Gerrit Reviews
For Gerrit Dashboard: QTBUG-129972 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
603930,12 | Implement read/write-backs for QVariantMap and QVariantHash | dev | qt/qtdeclarative | Status: NEW | 0 | -1 |