diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index ece24f8078..010957cf21 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -91,9 +91,6 @@ public: virtual QVariant styleHint(StyleHint hint) const; virtual void exec() = 0; - - virtual void deleteNativeDialog() = 0; - virtual bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) = 0; diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h index 263ccdc086..aaa2e26fc4 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h @@ -54,7 +54,6 @@ public: virtual ~QCocoaColorDialogHelper(); void exec(); - void deleteNativeDialog(); bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); void hide(); diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 7d245c3db6..d617d1d210 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -343,7 +343,12 @@ QCocoaColorDialogHelper::QCocoaColorDialogHelper() : } QCocoaColorDialogHelper::~QCocoaColorDialogHelper() -{ } +{ + if (!mDelegate) + return; + [reinterpret_cast(mDelegate) release]; + mDelegate = 0; +} void QCocoaColorDialogHelper::exec() { @@ -358,14 +363,6 @@ void QCocoaColorDialogHelper::exec() emit reject(); } -void QCocoaColorDialogHelper::deleteNativeDialog() -{ - if (!mDelegate) - return; - [reinterpret_cast(mDelegate) release]; - mDelegate = 0; -} - bool QCocoaColorDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent) { if (windowModality == Qt::WindowModal) { diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h index 76c4b87e11..9bdf3acd71 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h @@ -60,7 +60,6 @@ public: bool defaultNameFilterDisables() const; - void deleteNativeDialog(); bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); void hide(); void setDirectory(const QString &directory); diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index ccf9482e4f..30f4cabfae 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -511,7 +511,10 @@ QCocoaFileDialogHelper::QCocoaFileDialogHelper() QCocoaFileDialogHelper::~QCocoaFileDialogHelper() { - + if (!mDelegate) + return; + [reinterpret_cast(mDelegate) release]; + mDelegate = 0; } void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath) @@ -602,12 +605,6 @@ QString QCocoaFileDialogHelper::selectedNameFilter() const return index != -1 ? options()->nameFilters().at(index) : QString(); } -void QCocoaFileDialogHelper::deleteNativeDialog() -{ - [reinterpret_cast(mDelegate) release]; - mDelegate = 0; -} - void QCocoaFileDialogHelper::hide() { hideCocoaFilePanel(); diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h index 2e185b769a..8c041205a5 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h @@ -54,12 +54,10 @@ class QCocoaFontDialogHelper : public QPlatformFontDialogHelper { public: QCocoaFontDialogHelper(); - virtual ~QCocoaFontDialogHelper(); + ~QCocoaFontDialogHelper(); void exec(); - void deleteNativeDialog(); - bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); void hide(); diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index a70953d0df..088f6265ca 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -362,7 +362,12 @@ QCocoaFontDialogHelper::QCocoaFontDialogHelper() : } QCocoaFontDialogHelper::~QCocoaFontDialogHelper() -{ } +{ + if (!mDelegate) + return; + [reinterpret_cast(mDelegate) release]; + mDelegate = 0; +} void QCocoaFontDialogHelper::exec() { @@ -377,14 +382,6 @@ void QCocoaFontDialogHelper::exec() emit reject(); } -void QCocoaFontDialogHelper::deleteNativeDialog() -{ - if (!mDelegate) - return; - [reinterpret_cast(mDelegate) release]; - mDelegate = 0; -} - bool QCocoaFontDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent) { if (windowModality == Qt::WindowModal) { diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index e1aae23b8c..e283848236 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -425,6 +425,12 @@ QWindowsDialogHelperBase::QWindowsDialogHelperBase() : { } +template +QWindowsDialogHelperBase::~QWindowsDialogHelperBase() +{ + delete m_nativeDialog; +} + template QWindowsNativeDialogBase *QWindowsDialogHelperBase::nativeDialog() const { @@ -444,15 +450,6 @@ QWindowsNativeDialogBase *QWindowsDialogHelperBase::ensureNativeDialo return m_nativeDialog; } -template -void QWindowsDialogHelperBase::deleteNativeDialog() -{ - if (QWindowsContext::verboseDialogs) - qDebug("%s" , __FUNCTION__); - delete m_nativeDialog; - m_nativeDialog = 0; -} - /*! \class QWindowsDialogThread \brief Run a non-modal native dialog in a separate thread. diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h index a8e0de0383..b3c83f6501 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h @@ -67,7 +67,6 @@ class QWindowsDialogHelperBase : public BaseClass public: virtual void exec(); - virtual void deleteNativeDialog(); virtual bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); @@ -78,6 +77,7 @@ public: protected: QWindowsDialogHelperBase(); + ~QWindowsDialogHelperBase(); QWindowsNativeDialogBase *nativeDialog() const; private: diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index b0cc35340d..f3e0773eac 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -123,12 +123,12 @@ QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const return QPlatformDialogHelper::defaultStyleHint(hint); } -void QDialogPrivate::deleteNativeDialog() +void QDialogPrivate::deletePlatformHelper() { - if (QPlatformDialogHelper *helper = platformHelper()) { - helper->deleteNativeDialog(); - nativeDialogInUse = false; - } + delete m_platformHelper; + m_platformHelper = 0; + m_platformHelperCreated = false; + nativeDialogInUse = false; } /*! @@ -335,7 +335,6 @@ QDialog::~QDialog() } QT_CATCH(...) { // we're in the destructor - just swallow the exception } - d->deleteNativeDialog(); } /*! diff --git a/src/widgets/dialogs/qdialog_p.h b/src/widgets/dialogs/qdialog_p.h index 3b8a5edb0f..34d5c551fd 100644 --- a/src/widgets/dialogs/qdialog_p.h +++ b/src/widgets/dialogs/qdialog_p.h @@ -83,7 +83,7 @@ public: QWindow *parentWindow() const; bool setNativeDialogVisible(bool visible); QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const; - void deleteNativeDialog(); + void deletePlatformHelper(); QPointer mainDef; Qt::Orientation orientation; diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 15a85c98d9..057728e254 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1371,7 +1371,7 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) } d->retranslateWindowTitle(); // we need to recreate the native dialog when changing the AcceptMode - d->deleteNativeDialog(); + d->deletePlatformHelper(); // clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly setAttribute(Qt::WA_DontShowOnScreen, false); }