summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-02-04 09:11:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-07 23:52:49 +0100
commit29804462f4f7205ba941973e209642dfc81a5f14 (patch)
tree73b631f49e303cfd9805c0de7fb613962825018d /src
parent59892468c95946ae3c3c3360e46d39bd62d8b9ea (diff)
Windows file dialog: Clean up thread manually.
Do not use deleteLater() to delete the thread. Task-number: QTBUG-36357 Change-Id: Ie7c87b92a7c73d5fbac01d4951d387ee2facd05c Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.cpp29
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.h4
2 files changed, 29 insertions, 4 deletions
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
index 2abfb426cc..f0770d7d18 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
@@ -502,11 +502,31 @@ template <class BaseClass>
QWindowsDialogHelperBase<BaseClass>::QWindowsDialogHelperBase() :
m_nativeDialog(0),
m_ownerWindow(0),
- m_timerId(0)
+ m_timerId(0),
+ m_thread(0)
{
}
template <class BaseClass>
+void QWindowsDialogHelperBase<BaseClass>::cleanupThread()
+{
+ if (m_thread) { // Thread may be running if the dialog failed to close.
+ if (m_thread->isRunning())
+ m_thread->wait(500);
+ if (m_thread->isRunning()) {
+ m_thread->terminate();
+ m_thread->wait(300);
+ if (m_thread->isRunning())
+ qCCritical(lcQpaDialogs) <<__FUNCTION__ << "Failed to terminate thread.";
+ else
+ qCWarning(lcQpaDialogs) << __FUNCTION__ << "Thread terminated.";
+ }
+ delete m_thread;
+ m_thread = 0;
+ }
+}
+
+template <class BaseClass>
QWindowsNativeDialogBase *QWindowsDialogHelperBase<BaseClass>::nativeDialog() const
{
if (m_nativeDialog.isNull()) {
@@ -559,7 +579,6 @@ void QWindowsDialogThread::run()
{
qCDebug(lcQpaDialogs) << '>' << __FUNCTION__;
m_dialog->exec(m_owner);
- deleteLater();
qCDebug(lcQpaDialogs) << '<' << __FUNCTION__;
}
@@ -587,6 +606,7 @@ bool QWindowsDialogHelperBase<BaseClass>::show(Qt::WindowFlags,
// a subsequent call to exec() may follow. So, start an idle timer
// which will start the dialog thread. If exec() is then called, the
// timer is stopped and dialog->exec() is called directly.
+ cleanupThread();
if (modal) {
m_timerId = this->startTimer(0);
} else {
@@ -599,8 +619,9 @@ template <class BaseClass>
void QWindowsDialogHelperBase<BaseClass>::startDialogThread()
{
Q_ASSERT(!m_nativeDialog.isNull());
- QWindowsDialogThread *thread = new QWindowsDialogThread(m_nativeDialog, m_ownerWindow);
- thread->start();
+ Q_ASSERT(!m_thread);
+ m_thread = new QWindowsDialogThread(m_nativeDialog, m_ownerWindow);
+ m_thread->start();
stopTimer();
}
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h
index 1501b02bd9..bcf9f544b5 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h
@@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
class QFileDialog;
class QDialog;
+class QThread;
class QWindowsNativeDialogBase;
namespace QWindowsDialogs
@@ -68,6 +69,7 @@ class QWindowsDialogHelperBase : public BaseClass
Q_DISABLE_COPY(QWindowsDialogHelperBase)
public:
typedef QSharedPointer<QWindowsNativeDialogBase> QWindowsNativeDialogBasePtr;
+ ~QWindowsDialogHelperBase() { cleanupThread(); }
virtual void exec();
virtual bool show(Qt::WindowFlags windowFlags,
@@ -88,10 +90,12 @@ private:
inline QWindowsNativeDialogBase *ensureNativeDialog();
inline void startDialogThread();
inline void stopTimer();
+ void cleanupThread();
QWindowsNativeDialogBasePtr m_nativeDialog;
HWND m_ownerWindow;
int m_timerId;
+ QThread *m_thread;
};
QT_END_NAMESPACE