Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.15.14, 6.2.9, 6.5.2, 6.5.5-1, 6.6.0 Beta3, 6.7.0
-
Windows 10 22H2, MSVC 2019 x64
Description
Delegates are destroyed/pooled too often.
Note: Implementing similar code using ListView+ListModel does not exhibit this issue.
Code
import QtQuick 2.15 import QtQuick.Window 2.15 import Qt.labs.qmlmodels 1.0 Window { width: 640 height: 480 visible: true TableView { id: view anchors.fill: parent reuseItems: false model: TableModel { id: tableModel TableModelColumn { display: "A" } } delegate: Text { required property int modelData text: modelData TableView.onPooled: console.log("Pooled:", text) TableView.onReused: console.log("Reused:", text) Component.onCompleted: console.log("New:", text) Component.onDestruction: console.log("Destroyed:", text) } Timer { property int i: 0 interval: 1000 running: true repeat: true onTriggered: { console.log(`=== Row ${i} ===`) if (tableModel.rowCount >= 5) tableModel.removeRow(0) tableModel.appendRow( {"A": i++} ) } } } }
Expected Output
If reuseItems == false
qml: === Row 0 === qml: New: 0 qml: === Row 1 === qml: New: 1 qml: === Row 2 === qml: New: 2 qml: === Row 3 === qml: New: 3 qml: === Row 4 === qml: New: 4 qml: === Row 5 === qml: Destroyed: 0 qml: New: 5 ...
If reuseItems == true
qml: === Row 0 === qml: New: 0 qml: === Row 1 === qml: New: 1 qml: === Row 2 === qml: New: 2 qml: === Row 3 === qml: New: 3 qml: === Row 4 === qml: New: 4 qml: === Row 5 === qml: Pooled: 0 qml: Reused: 5 ...
Actual Output
If reuseItems == false
qml: === Row 0 === qml: New: 0 qml: === Row 1 === qml: Destroyed: 0 qml: New: 0 qml: New: 1 qml: === Row 2 === qml: Destroyed: 1 qml: Destroyed: 0 qml: New: 0 qml: New: 1 qml: New: 2 qml: === Row 3 === qml: Destroyed: 1 qml: Destroyed: 0 qml: Destroyed: 2 qml: New: 0 qml: New: 1 qml: New: 2 qml: New: 3 qml: === Row 4 === qml: Destroyed: 1 qml: Destroyed: 3 qml: Destroyed: 0 qml: Destroyed: 2 qml: New: 0 qml: New: 1 qml: New: 2 qml: New: 3 qml: New: 4 qml: === Row 5 === qml: Destroyed: 4 qml: Destroyed: 1 qml: Destroyed: 3 qml: Destroyed: 0 qml: Destroyed: 2 qml: New: 1 qml: New: 2 qml: New: 3 qml: New: 4 qml: New: 5 ...
If reuseItems == true
qml: === Row 0 === qml: New: 0 qml: === Row 1 === qml: Pooled: 0 qml: Reused: 0 qml: New: 1 qml: === Row 2 === qml: Pooled: 0 qml: Pooled: 1 qml: Reused: 0 qml: Reused: 1 qml: New: 2 qml: === Row 3 === qml: Pooled: 2 qml: Pooled: 0 qml: Pooled: 1 qml: Reused: 0 qml: Reused: 1 qml: Reused: 2 qml: New: 3 qml: === Row 4 === qml: Pooled: 2 qml: Pooled: 0 qml: Pooled: 1 qml: Pooled: 3 qml: Reused: 0 qml: Reused: 1 qml: Reused: 2 qml: Reused: 3 qml: New: 4 qml: === Row 5 === qml: Pooled: 2 qml: Pooled: 4 qml: Pooled: 0 qml: Pooled: 1 qml: Pooled: 3 qml: Reused: 1 qml: Reused: 2 qml: Reused: 3 qml: Reused: 4 qml: Reused: 5 ...
Attachments
Issue Links
- duplicates
-
QTBUG-116650 TableView rebuilds the entire table when a single row is added/removed
- Reported
- is duplicated by
-
QTBUG-119144 QML Views: Too many delegates instantiated unnecessarily with (begin|end)InsertRows()
- Closed
- is required for
-
QTBUG-70326 TableView
- In Progress