Details
-
Suggestion
-
Resolution: Unresolved
-
P1: Critical
-
None
-
bbf2c0322 (dev), 4bd5b3127 (dev), f469d538a (dev), 3bc0a1140 (dev), 1cf72c90d (dev), 9ee136918 (dev)
Description
Code
Adapted from https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html#changing-model-data
import QtQuick import QtQuick.Controls.Basic import MyApp Window { width: 800 height: 600 visible: true ListView { anchors.fill: parent model: EditableModel {} delegate: TextField { required property var model required property string display width: ListView.view.width text: display Keys.onReturnPressed: model.edit = text } } }
Shortcomings
The code above seems to be the "best" that can be done as of Qt 6.8.1. There are some unavoidable gaps:
1. Can't use strong typing
We must use the weakly-typed "required property var model". Changing it to "required property EditableModel model" causes "model.edit = text" to fail at runtime:
Main.qml:19: TypeError: Value is null and could not be converted to an object
2. QML tools can't understand the code
Warning: Main.qml:19:39: Could not compile binding for onReturnPressed: Type (component in Main.qml)::model with type QVariant does not have a property edit for writing [compiler] Keys.onReturnPressed: model.edit = text ^^^^
(Even if we can use required property EditableModel model, this problem persists)
Attachments
Issue Links
- relates to
-
QTBUG-21558 Allow creating two way bindings in QML
-
- In Progress
-
Gerrit Reviews
For Gerrit Dashboard: QTBUG-132420 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
626839,5 | WIP: Allow user-overridden QQmlDelegateModelItem | dev | qt/qtdeclarative | Status: ABANDONED | -2 | 0 |
626915,5 | QmlModels: Centralize properties in QQmlDelegateModelItem | dev | qt/qtdeclarative | Status: ABANDONED | 0 | 0 |
627848,25 | QtQml: Add sticky bit to QQmlAbstractBinding | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
627849,32 | Use sticky bindings to write the model through required properties | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
628559,29 | Expose delegateModelAccess from QQuickItemView | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
630280,24 | Expose delegateModelAccess from QQuickRepeater | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
630508,19 | Quick: Expose delegateModelAccess from QQuickTableView | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
631002,14 | Doc: Update documentation about writing the model from delegates | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |