summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qinputdialog.cpp
diff options
context:
space:
mode:
authorTatiana Borisova <tatiana.borisova@qt.io>2024-08-27 16:55:22 +0200
committerTatiana Borisova <tatiana.borisova@qt.io>2024-09-14 21:28:42 +0200
commit81d55f772892445686862e49d0a6092668f8c725 (patch)
treeb58a6621c84e98e5ae8138cdd5953bff7e13387e /src/widgets/dialogs/qinputdialog.cpp
parenta76ce7b191933edcba181e888fa62d1a8fa83a49 (diff)
QDialogs: prevent crash in static get*() functions when parent gets deleted
- As explained in https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application-and-how-fix-it-0 creating dialogs on the stack is a bad idea, if the application or the dialog's parent window can be closed by means other than user interaction (such as a timer or an IPC call). Since we cannot know whether Qt is used to build such an application, we must assume it is, create the dialog on the heap, and monitor its lifetime with a QPointer. Long time ago instead of using manual resource management, QAutoPointer was added to fix the crash problem for QInputDialog. The same fix now is being applied for the rest of QDialog classes: QColorDialog, QFileDialog, QFontDialog. Documentation warnings about deleting the parent are not actual anymore. Deleted. Task-number: QTBUG-54693 Change-Id: Ib7cc0575ea25f392a295538e21de9015dc49ebe4 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qinputdialog.cpp')
-rw-r--r--src/widgets/dialogs/qinputdialog.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp
index b4229c18000..2a6413c2478 100644
--- a/src/widgets/dialogs/qinputdialog.cpp
+++ b/src/widgets/dialogs/qinputdialog.cpp
@@ -1149,7 +1149,7 @@ QString QInputDialog::getText(QWidget *parent, const QString &title, const QStri
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
- if (ret) {
+ if (bool(dialog) && ret) {
return dialog->textValue();
} else {
return QString();
@@ -1197,7 +1197,7 @@ QString QInputDialog::getMultiLineText(QWidget *parent, const QString &title, co
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
- if (ret) {
+ if (bool(dialog) && ret) {
return dialog->textValue();
} else {
return QString();
@@ -1242,7 +1242,7 @@ int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &l
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
- if (ret) {
+ if (bool(dialog) && ret) {
return dialog->intValue();
} else {
return value;
@@ -1291,7 +1291,7 @@ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QStr
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
- if (ret) {
+ if (bool(dialog) && ret) {
return dialog->doubleValue();
} else {
return value;
@@ -1344,7 +1344,7 @@ QString QInputDialog::getItem(QWidget *parent, const QString &title, const QStri
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
- if (ret) {
+ if (bool(dialog) && ret) {
return dialog->textValue();
} else {
return text;