QDialogButtonBox: properly clear buttons in setStandardButtons()
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.5 Change-Id: I867086855cfde88a7b22a5579662f250b9db0042 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 0e5d5513279cff61673adc2ace5ed27202bbdc97) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9a504780b9
commit
4b47d64f15
@ -647,12 +647,12 @@ void QDialogButtonBox::clear()
|
|||||||
d->standardButtonHash.clear();
|
d->standardButtonHash.clear();
|
||||||
for (int i = 0; i < NRoles; ++i) {
|
for (int i = 0; i < NRoles; ++i) {
|
||||||
QList<QAbstractButton *> &list = d->buttonLists[i];
|
QList<QAbstractButton *> &list = d->buttonLists[i];
|
||||||
while (list.size()) {
|
for (auto button : std::as_const(list)) {
|
||||||
QAbstractButton *button = list.takeAt(0);
|
|
||||||
QObjectPrivate::disconnect(button, &QAbstractButton::destroyed,
|
QObjectPrivate::disconnect(button, &QAbstractButton::destroyed,
|
||||||
d, &QDialogButtonBoxPrivate::handleButtonDestroyed);
|
d, &QDialogButtonBoxPrivate::handleButtonDestroyed);
|
||||||
delete button;
|
delete button;
|
||||||
}
|
}
|
||||||
|
list.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,8 +818,8 @@ void QDialogButtonBox::setStandardButtons(StandardButtons buttons)
|
|||||||
{
|
{
|
||||||
Q_D(QDialogButtonBox);
|
Q_D(QDialogButtonBox);
|
||||||
// Clear out all the old standard buttons, then recreate them.
|
// Clear out all the old standard buttons, then recreate them.
|
||||||
qDeleteAll(d->standardButtonHash.keyBegin(), d->standardButtonHash.keyEnd());
|
const auto toDelete = std::exchange(d->standardButtonHash, {});
|
||||||
d->standardButtonHash.clear();
|
qDeleteAll(toDelete.keyBegin(), toDelete.keyEnd());
|
||||||
|
|
||||||
d->createStandardButtons(buttons);
|
d->createStandardButtons(buttons);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user