summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-04-28 19:04:41 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-05-05 10:03:27 +0200
commit0e5d5513279cff61673adc2ace5ed27202bbdc97 (patch)
tree421723eb0cf64161be6f56b82c440ae4627f3b30
parent65fef44ddf18c2dbc7357ff056a28a308b1350f2 (diff)
QDialogButtonBox: properly clear buttons in setStandardButtons()HEADdev
When setting new buttons with setStandardButtons(), the old ones are deleted by iterating over d->standardButtonHash. But this hash is modified when a button is destroyed and therefore sometimes not all buttons were deleted. This amends df735d794fd2e545c18b9e345e833422bcd64329. Fixes: QTBUG-123939 Pick-to: 6.7 6.5 Change-Id: I867086855cfde88a7b22a5579662f250b9db0042 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
-rw-r--r--src/widgets/widgets/qdialogbuttonbox.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp
index 30ace89fa8..30c68ad18b 100644
--- a/src/widgets/widgets/qdialogbuttonbox.cpp
+++ b/src/widgets/widgets/qdialogbuttonbox.cpp
@@ -647,12 +647,12 @@ void QDialogButtonBox::clear()
d->standardButtonHash.clear();
for (int i = 0; i < NRoles; ++i) {
QList<QAbstractButton *> &list = d->buttonLists[i];
- while (list.size()) {
- QAbstractButton *button = list.takeAt(0);
+ for (auto button : std::as_const(list)) {
QObjectPrivate::disconnect(button, &QAbstractButton::destroyed,
d, &QDialogButtonBoxPrivate::handleButtonDestroyed);
delete button;
}
+ list.clear();
}
}
@@ -818,8 +818,8 @@ void QDialogButtonBox::setStandardButtons(StandardButtons buttons)
{
Q_D(QDialogButtonBox);
// Clear out all the old standard buttons, then recreate them.
- qDeleteAll(d->standardButtonHash.keyBegin(), d->standardButtonHash.keyEnd());
- d->standardButtonHash.clear();
+ const auto toDelete = std::exchange(d->standardButtonHash, {});
+ qDeleteAll(toDelete.keyBegin(), toDelete.keyEnd());
d->createStandardButtons(buttons);
}