Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.4.0, 6.4.1, 6.4.2
-
Ubuntu 22.04
-
-
6b4939df5 (dev), d71ed94e2 (6.5), 8e4065ad3 (tqtc/lts-6.2), 2ff14d18c (tqtc/lts-5.15)
Description
If to TableModel connect/disconnect TableView with HorizontalHeaderView and/or VerticalHeaderView the QQmlTableModel::headerDataChanged signal will not be disconnected from TableVievs (even if TableView will be destroyed).
In app what I develop it crash after several minutes of using the app. I can not reproduce crash in demo app. Image below is crash from the app:
How to reproduce (connections leak not crash):
- Build and run attached HeaderViewsConnectionsLeak project.
- On application press several times Reload button.
- On Application Output you can see more and more connections to signal:
signal: headerDataChanged(Qt::Orientation,int,int)
<functor or function pointer>
...
SIGNALS IN
<-- QQmlTableModel::unnamed <unknown>
Root cause:
The root cause is in qquickheaderview.cpp
Connect to &QAbstractItemModel::headerDataChanged is implemented as lambda but disconnect only from class instance:
// void QHeaderDataProxyModel::connectToModel() { if (m_model.isNull()) return; connect(m_model, &QAbstractItemModel::headerDataChanged, [this](Qt::Orientation orient, int first, int last) { if (orient != orientation()) return; if (orient == Qt::Horizontal) { emit dataChanged(createIndex(0, first), createIndex(0, last)); } else { emit dataChanged(createIndex(first, 0), createIndex(last, 0)); } }); ... void QHeaderDataProxyModel::disconnectFromModel() { if (m_model.isNull()) return; m_model->disconnect(this); }
How to fix:
Implement the connection to headerDataChanged as it is with all another slots in the method void QHeaderDataProxyModel::connectToModel()