summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-12-11 15:42:02 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2023-12-18 12:12:30 +0100
commit7120859fdb34cb7d80a183f1a8327b88d0fa7e10 (patch)
tree4fcb8515de64ed93ebd80bd1ba66b4c268c6faae /src/widgets/widgets/qcombobox.cpp
parent87f7d2c6b076a4c275d4d14a1e099844c9eb4766 (diff)
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 in ecef7046245f3adee9366d3543e4ed2a09f65735 and 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 after 5093e517b924074ab6e63658c87237be315a17e6 even without the previous fix ecef7046245f3adee9366d3543e4ed2a09f65735 in 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 for ecef7046245f3adee9366d3543e4ed2a09f65735). [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>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index b766595d83..d62c7628d0 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -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);
}