summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemwatcher_win.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-07-06 13:37:44 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-07-14 04:20:07 +0000
commit5e66767fca9908c397705ed557b106ec2c3a63f8 (patch)
tree057e0a91cc69c72ce71f93005d005d924ea9978f /src/corelib/io/qfilesystemwatcher_win.cpp
parent56d52e1f1a8709520b62b558121237686acf5fae (diff)
Make sure there's an event dispatcher in QWindowsRemovableDriveListener
In order to add the listener, we need to hook into the internal HWND. Creating the QThreadData (thus adopting the thread) and the event dispatcher are ok because they would happen anyway. QFileSystemWatcher works only with the Qt event loop. [ChangeLog][QtCore][QFileSystemWatcher] Fixed a bug that caused addPaths() to crash on Windows if adding a path to be watched on removeable storage, if that addPaths() was called on a thread not created by QThread and no QEventLoop has been created yet. Task-number: QTBUG-69320 Change-Id: If48c5c2e920c433298f1fffd153ee20bea56c62f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_win.cpp')
-rw-r--r--src/corelib/io/qfilesystemwatcher_win.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp
index 9e43d11e71..3a49f4346b 100644
--- a/src/corelib/io/qfilesystemwatcher_win.cpp
+++ b/src/corelib/io/qfilesystemwatcher_win.cpp
@@ -57,6 +57,7 @@
# include <qcoreapplication.h>
# include <qdir.h>
# include <private/qeventdispatcher_win_p.h>
+# include <private/qthread_p.h>
# include <dbt.h>
# include <algorithm>
# include <vector>
@@ -308,7 +309,8 @@ void QWindowsRemovableDriveListener::addPath(const QString &p)
notify.dbch_size = sizeof(notify);
notify.dbch_devicetype = DBT_DEVTYP_HANDLE;
notify.dbch_handle = volumeHandle;
- QEventDispatcherWin32 *winEventDispatcher = static_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance());
+ QThreadData *currentData = QThreadData::current();
+ QEventDispatcherWin32 *winEventDispatcher = static_cast<QEventDispatcherWin32 *>(currentData->ensureEventDispatcher());
re.devNotify = RegisterDeviceNotification(winEventDispatcher->internalHwnd(),
&notify, DEVICE_NOTIFY_WINDOW_HANDLE);
// Empirically found: The notifications also work when the handle is immediately