a11y: QComboBox: Reset all model connections when setting model
When setting the model either directly for the combobox itself or for the combobox's view, disconnect from the model signals and connect to them anew. Always set the model for the view first before connecting the combobox's own slots to the model's signals. Since slots are activated in the order in which they are connected [1] and both of them are connected to the QAbstractItemModel::rowsInserted signal, this ensures that the QAbstractItemViewPrivate::rowsInserted/QListView::rowsInserted slot will get activated before the QComboBoxPrivate::rowsInserted one. (QAbstractItemView::setModel connects its slots to the model's signals.) Activating these slots the other way around is problematic as described in more detail inbb10ecef704624and QTBUG-120121. (macOS accessibility bridge depends on QAbstractItemViewPrivate::rowsInserted to update its table representation, which may be necessary before activating other slots; ATs or platform a11y caches may depend on correct event order.) In a quick test, this commit fixes the QTBUG-119526 crash reliably reproducible after5093e517b9even without the previous fixecef704624in place. However, leave that one in place, too, as relying on the order in which the connected slots are called is quite fragile (s. the discussion in the Gerrit change forecef704624). [1] https://doc.qt.io/qt-6/qobject.html#connect Fixes: QTBUG-120121 Task-number: QTBUG-119526 Pick-to: 6.7 6.6 6.5 Change-Id: If75fef661f7fcfc1e30e90ec851a2555cf25a65d Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
parent
87f7d2c6b0
commit
7120859fdb
|
|
@ -1064,7 +1064,9 @@ QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()
|
|||
|
||||
Q_Q(QComboBox);
|
||||
container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);
|
||||
disconnectModel();
|
||||
container->itemView()->setModel(model);
|
||||
connectModel();
|
||||
container->itemView()->setTextElideMode(Qt::ElideMiddle);
|
||||
updateDelegate(true);
|
||||
updateLayoutDirection();
|
||||
|
|
@ -2055,7 +2057,6 @@ void QComboBox::setModel(QAbstractItemModel *model)
|
|||
}
|
||||
|
||||
d->model = model;
|
||||
d->connectModel();
|
||||
|
||||
if (d->container) {
|
||||
d->container->itemView()->setModel(model);
|
||||
|
|
@ -2064,6 +2065,8 @@ void QComboBox::setModel(QAbstractItemModel *model)
|
|||
d, &QComboBoxPrivate::emitHighlighted, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
d->connectModel();
|
||||
|
||||
setRootModelIndex(QModelIndex());
|
||||
|
||||
d->trySetValidIndex();
|
||||
|
|
@ -2487,8 +2490,11 @@ void QComboBox::setView(QAbstractItemView *itemView)
|
|||
return;
|
||||
}
|
||||
|
||||
if (itemView->model() != d->model)
|
||||
if (itemView->model() != d->model) {
|
||||
d->disconnectModel();
|
||||
itemView->setModel(d->model);
|
||||
d->connectModel();
|
||||
}
|
||||
d->viewContainer()->setItemView(itemView);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue