summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-08-07 13:53:05 -0700
committerSimon Hausmann <simon.hausmann@qt.io>2017-08-08 11:48:10 +0200
commit883dfb3d156431eeb3ffc8f02a09c89bb7fa7d46 (patch)
treed4c2b3d096e1d5c64be698b5d0cd8c8bae35b2b4 /src/corelib/io
parent5a9b1425e187bc77122354cf7446bcf6bb322ff4 (diff)
parentb75bc0f75c09b192dba68449b009cdf175519dbd (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/widgets/kernel/qwidget.cpp This merge also extends the expected output of the pairdiagnostics teamcity output (added in dev in commit c608ffc56ab37f9a9d5b9c34543126adb89e2b08) after the recent addition of the flowId attribute to the teamcity output (commit 8f036562119dd35ce51dc9230304d893b906bd37 in 5.9). Change-Id: I3868166e5efc45538544fffd14d8aba438f9173c
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfile.cpp4
-rw-r--r--src/corelib/io/qfiledevice.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_win.cpp45
-rw-r--r--src/corelib/io/qfilesystemwatcher_win_p.h2
4 files changed, 29 insertions, 24 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index c1d5abdf7b..5b487a1339 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -1054,11 +1054,13 @@ bool QFile::resize(qint64 sz)
/*!
\overload
- Sets \a fileName to size (in bytes) \a sz. Returns \c true if the file if
+ Sets \a fileName to size (in bytes) \a sz. Returns \c true if
the resize succeeds; false otherwise. If \a sz is larger than \a
fileName currently is the new bytes will be set to 0, if \a sz is
smaller the file is simply truncated.
+ \warning This function can fail if the file doesn't exist.
+
\sa resize()
*/
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp
index ab37d6f4d7..2f99775c65 100644
--- a/src/corelib/io/qfiledevice.cpp
+++ b/src/corelib/io/qfiledevice.cpp
@@ -615,6 +615,8 @@ qint64 QFileDevice::size() const
currently is, the new bytes will be set to 0; if \a sz is smaller, the
file is simply truncated.
+ \warning This function can fail if the file doesn't exist.
+
\sa size()
*/
bool QFileDevice::resize(qint64 sz)
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp
index 2b5cb63282..cdb79e7c97 100644
--- a/src/corelib/io/qfilesystemwatcher_win.cpp
+++ b/src/corelib/io/qfilesystemwatcher_win.cpp
@@ -127,16 +127,10 @@ private:
quintptr m_lastMessageHash;
};
-static inline QEventDispatcherWin32 *winEventDispatcher()
-{
- return static_cast<QEventDispatcherWin32 *>(QCoreApplication::instance()->eventDispatcher());
-}
-
QWindowsRemovableDriveListener::QWindowsRemovableDriveListener(QObject *parent)
: QObject(parent)
, m_lastMessageHash(0)
{
- winEventDispatcher()->installNativeEventFilter(this);
}
static void stopDeviceNotification(QWindowsRemovableDriveListener::RemovableDriveEntry &e)
@@ -314,7 +308,8 @@ void QWindowsRemovableDriveListener::addPath(const QString &p)
notify.dbch_size = sizeof(notify);
notify.dbch_devicetype = DBT_DEVTYP_HANDLE;
notify.dbch_handle = volumeHandle;
- re.devNotify = RegisterDeviceNotification(winEventDispatcher()->internalHwnd(),
+ QEventDispatcherWin32 *winEventDispatcher = static_cast<QEventDispatcherWin32 *>(QCoreApplication::eventDispatcher());
+ re.devNotify = RegisterDeviceNotification(winEventDispatcher->internalHwnd(),
&notify, DEVICE_NOTIFY_WINDOW_HANDLE);
// Empirically found: The notifications also work when the handle is immediately
// closed. Do it here to avoid having to close/reopen in lock message handling.
@@ -339,20 +334,24 @@ QWindowsFileSystemWatcherEngine::Handle::Handle()
QWindowsFileSystemWatcherEngine::QWindowsFileSystemWatcherEngine(QObject *parent)
: QFileSystemWatcherEngine(parent)
-#ifndef Q_OS_WINRT
- , m_driveListener(new QWindowsRemovableDriveListener(this))
-#endif
{
#ifndef Q_OS_WINRT
- parent->setProperty("_q_driveListener",
- QVariant::fromValue(static_cast<QObject *>(m_driveListener)));
- QObject::connect(m_driveListener, &QWindowsRemovableDriveListener::driveLockForRemoval,
- this, &QWindowsFileSystemWatcherEngine::driveLockForRemoval);
- QObject::connect(m_driveListener, &QWindowsRemovableDriveListener::driveLockForRemovalFailed,
- this, &QWindowsFileSystemWatcherEngine::driveLockForRemovalFailed);
- QObject::connect(m_driveListener,
- QOverload<const QString &>::of(&QWindowsRemovableDriveListener::driveRemoved),
- this, &QWindowsFileSystemWatcherEngine::driveRemoved);
+ if (QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher()) {
+ m_driveListener = new QWindowsRemovableDriveListener(this);
+ eventDispatcher->installNativeEventFilter(m_driveListener);
+ parent->setProperty("_q_driveListener",
+ QVariant::fromValue(static_cast<QObject *>(m_driveListener)));
+ QObject::connect(m_driveListener, &QWindowsRemovableDriveListener::driveLockForRemoval,
+ this, &QWindowsFileSystemWatcherEngine::driveLockForRemoval);
+ QObject::connect(m_driveListener, &QWindowsRemovableDriveListener::driveLockForRemovalFailed,
+ this, &QWindowsFileSystemWatcherEngine::driveLockForRemovalFailed);
+ QObject::connect(m_driveListener,
+ QOverload<const QString &>::of(&QWindowsRemovableDriveListener::driveRemoved),
+ this, &QWindowsFileSystemWatcherEngine::driveRemoved);
+ } else {
+ qWarning("QFileSystemWatcher: Removable drive notification will not work"
+ " if there is no QCoreApplication instance.");
+ }
#endif // !Q_OS_WINRT
}
@@ -518,9 +517,11 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
}
#ifndef Q_OS_WINRT
- for (const QString &path : paths) {
- if (!p.contains(path))
- m_driveListener->addPath(path);
+ if (Q_LIKELY(m_driveListener)) {
+ for (const QString &path : paths) {
+ if (!p.contains(path))
+ m_driveListener->addPath(path);
+ }
}
#endif // !Q_OS_WINRT
return p;
diff --git a/src/corelib/io/qfilesystemwatcher_win_p.h b/src/corelib/io/qfilesystemwatcher_win_p.h
index 51c7082483..8322fc170a 100644
--- a/src/corelib/io/qfilesystemwatcher_win_p.h
+++ b/src/corelib/io/qfilesystemwatcher_win_p.h
@@ -129,7 +129,7 @@ signals:
private:
QList<QWindowsFileSystemWatcherEngineThread *> threads;
#ifndef Q_OS_WINRT
- QWindowsRemovableDriveListener *m_driveListener;
+ QWindowsRemovableDriveListener *m_driveListener = nullptr;
#endif
};