summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2012-05-08 10:29:45 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-09 01:36:09 +0200
commitcf48eded4dc0e6c860b48a1d756b5920ffc6a724 (patch)
tree257d329f30bdea003c09fd3ff842686485d8f2de /src
parentf280efc6201adf8933c9d48a1d5b6983ee9fed9b (diff)
Don't leak native dialog resources
Have QDialog::~QDialog() call deleteNativeDialog_sys() on the helpers, so that we don't risk leaking any resources allocated in the helper. QFileDialog does this now, but not QColorDialog or QFontDialog. The Cocoa plugin worked around this problem by calling deleteNativeDialog_sys() itself, but the Windows plugin does not do this, resulting in leaks. Change-Id: I380d87c95686c8f3cb260f9242299be27329280d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm4
-rw-r--r--src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm4
-rw-r--r--src/widgets/dialogs/qdialog.cpp10
-rw-r--r--src/widgets/dialogs/qdialog_p.h1
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp8
-rw-r--r--src/widgets/dialogs/qfiledialog_p.h10
6 files changed, 16 insertions, 21 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
index 9f4446b32e..45c36b4e1e 100644
--- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm
@@ -343,9 +343,7 @@ QCocoaColorDialogHelper::QCocoaColorDialogHelper() :
}
QCocoaColorDialogHelper::~QCocoaColorDialogHelper()
-{
- deleteNativeDialog_sys();
-}
+{ }
void QCocoaColorDialogHelper::platformNativeDialogModalHelp()
{
diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
index 515bc2a6ee..5f39531503 100644
--- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
@@ -362,9 +362,7 @@ QCocoaFontDialogHelper::QCocoaFontDialogHelper() :
}
QCocoaFontDialogHelper::~QCocoaFontDialogHelper()
-{
- deleteNativeDialog_sys();
-}
+{ }
void QCocoaFontDialogHelper::platformNativeDialogModalHelp()
{
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 82a7b1a30d..44463b8d32 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -132,6 +132,14 @@ QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const
return QPlatformDialogHelper::defaultStyleHint(hint);
}
+void QDialogPrivate::deleteNativeDialog()
+{
+ if (QPlatformDialogHelper *helper = platformHelper()) {
+ helper->deleteNativeDialog_sys();
+ nativeDialogInUse = false;
+ }
+}
+
/*!
\class QDialog
\brief The QDialog class is the base class of dialog windows.
@@ -328,6 +336,7 @@ QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f)
QDialog::~QDialog()
{
+ Q_D(QDialog);
QT_TRY {
// Need to hide() here, as our (to-be) overridden hide()
// will not be called in ~QWidget.
@@ -335,6 +344,7 @@ 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 8c53d6a404..7b02f359dd 100644
--- a/src/widgets/dialogs/qdialog_p.h
+++ b/src/widgets/dialogs/qdialog_p.h
@@ -84,6 +84,7 @@ public:
QWindow *parentWindow() const;
bool setNativeDialogVisible(bool visible);
QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const;
+ void deleteNativeDialog();
QPointer<QPushButton> mainDef;
Qt::Orientation orientation;
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index 3908daec9c..15a85c98d9 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -362,13 +362,11 @@ QFileDialog::QFileDialog(const QFileDialogArgs &args)
*/
QFileDialog::~QFileDialog()
{
- Q_D(QFileDialog);
#ifndef QT_NO_SETTINGS
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
settings.beginGroup(QLatin1String("Qt"));
settings.setValue(QLatin1String("filedialog"), saveState());
#endif
- d->deleteNativeDialog_sys();
}
/*!
@@ -1372,10 +1370,10 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode)
d->qFileDialogUi->lookInCombo->setEditable(false);
}
d->retranslateWindowTitle();
-#if defined(Q_OS_MAC)
- d->deleteNativeDialog_sys();
+ // we need to recreate the native dialog when changing the AcceptMode
+ d->deleteNativeDialog();
+ // clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly
setAttribute(Qt::WA_DontShowOnScreen, false);
-#endif
}
/*
diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h
index a66ee757f6..4283842b1d 100644
--- a/src/widgets/dialogs/qfiledialog_p.h
+++ b/src/widgets/dialogs/qfiledialog_p.h
@@ -244,7 +244,6 @@ public:
// dialog. Returning false means that a non-native dialog must be
// used instead.
bool canBeNativeDialog();
- void deleteNativeDialog_sys();
QDialog::DialogCode dialogResultCode_sys();
void setDirectory_sys(const QString &directory);
@@ -347,15 +346,6 @@ inline QString QFileDialogPrivate::rootPath() const {
return model->rootPath();
}
-// Dummies for platforms that don't use native dialogs:
-inline void QFileDialogPrivate::deleteNativeDialog_sys()
-{
- if (QPlatformFileDialogHelper *helper = platformFileDialogHelper()) {
- helper->deleteNativeDialog_sys();
- nativeDialogInUse = false;
- }
-}
-
inline QDialog::DialogCode QFileDialogPrivate::dialogResultCode_sys()
{
QDialog::DialogCode result = QDialog::Rejected;