From 29804462f4f7205ba941973e209642dfc81a5f14 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 4 Feb 2014 09:11:01 +0100 Subject: 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 Reviewed-by: Joerg Bornemann --- .../platforms/windows/qwindowsdialoghelpers.cpp | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsdialoghelpers.cpp') 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,10 +502,30 @@ template QWindowsDialogHelperBase::QWindowsDialogHelperBase() : m_nativeDialog(0), m_ownerWindow(0), - m_timerId(0) + m_timerId(0), + m_thread(0) { } +template +void QWindowsDialogHelperBase::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 QWindowsNativeDialogBase *QWindowsDialogHelperBase::nativeDialog() const { @@ -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::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 void QWindowsDialogHelperBase::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(); } -- cgit v1.2.3