QFilesystemWatcher/Windows: Use event dispatcher of thread

Previously, the native event filter listening on removable drivers
was installed on QCoreApplication::eventDispatcher() which led to
a mismatch when launched from a non-GUI thread since
~QAbstractNativeEventFilter() removes itself from
QAbstractEventDispatcher::instance().
Amends 45580aa925,
e612fe8d47.

Task-number: QTBUG-64171
Change-Id: Icbe289bd585f124d66989d0cd574040b986e680c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Friedemann Kleint 2017-11-02 08:56:09 +01:00
parent ca0f05ebe2
commit 851c226247

View File

@ -308,7 +308,7 @@ 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 *>(QCoreApplication::eventDispatcher());
QEventDispatcherWin32 *winEventDispatcher = static_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance());
re.devNotify = RegisterDeviceNotification(winEventDispatcher->internalHwnd(),
&notify, DEVICE_NOTIFY_WINDOW_HANDLE);
// Empirically found: The notifications also work when the handle is immediately
@ -336,7 +336,7 @@ QWindowsFileSystemWatcherEngine::QWindowsFileSystemWatcherEngine(QObject *parent
: QFileSystemWatcherEngine(parent)
{
#ifndef Q_OS_WINRT
if (QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher()) {
if (QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance()) {
m_driveListener = new QWindowsRemovableDriveListener(this);
eventDispatcher->installNativeEventFilter(m_driveListener);
parent->setProperty("_q_driveListener",