diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index c4cc21cbe5..8e699e87c5 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1862,12 +1862,14 @@ void QColorDialogPrivate::retranslateStrings() bool QColorDialogPrivate::canBeNativeDialog() const { - Q_Q(const QColorDialog); + // Don't use Q_Q here! This function is called from ~QDialog, + // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). + const QDialog * const q = static_cast(q_ptr); if (nativeDialogInUse) return true; if (q->testAttribute(Qt::WA_DontShowOnScreen)) return false; - if (q->options() & QColorDialog::DontUseNativeDialog) + if (options->options() & QColorDialog::DontUseNativeDialog) return false; QLatin1String staticName(QColorDialog::staticMetaObject.className()); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index bc2de899f5..3aa9052917 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -695,12 +695,14 @@ void QFileDialogPrivate::emitFilesSelected(const QStringList &files) bool QFileDialogPrivate::canBeNativeDialog() const { - Q_Q(const QFileDialog); + // Don't use Q_Q here! This function is called from ~QDialog, + // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()). + const QDialog * const q = static_cast(q_ptr); if (nativeDialogInUse) return true; if (q->testAttribute(Qt::WA_DontShowOnScreen)) return false; - if (q->options() & QFileDialog::DontUseNativeDialog) + if (options->options() & QFileDialog::DontUseNativeDialog) return false; QLatin1String staticName(QFileDialog::staticMetaObject.className());