Core: Wrap moribund dialogs into QPointer

There's no guarantee that items in the collected list don't die for
other reasons before it's their turn in the loop.

Change-Id: I5e81a25c3c205646eece30d6dd1a95f4b97eda05
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-03-04 14:50:27 +01:00
parent 50c4046593
commit 6d6ec00cdb

View File

@@ -2189,16 +2189,18 @@ void ICorePrivate::openFileFromDevice()
static void acceptModalDialogs()
{
const QWidgetList topLevels = QApplication::topLevelWidgets();
QList<QDialog *> dialogsToClose;
QList<QPointer<QDialog>> dialogsToClose;
for (QWidget *topLevel : topLevels) {
if (auto dialog = qobject_cast<QDialog *>(topLevel)) {
if (dialog->isModal())
dialogsToClose.append(dialog);
}
}
for (QDialog *dialog : dialogsToClose)
for (QDialog *dialog : dialogsToClose) {
if (dialog)
dialog->accept();
}
}
} // Internal