QPollingFileSystemWatcherEngine: replace QTimer with QBasicTimer

We already have a QObject (*this), so we don't need another one in the
form of a QTimer; we can just let QTimerEvents be delivered to *this.

Changes surprisingly little code, because the code used start(int)
already.

Mark the timerEvent() final to avoid surprises from potential
further-derived classes.

Change-Id: Ib4ee8f8f6b9995d67d964afb231e913a00a76af3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 22858ffcedda16cd9f773df9ec74a5bff72a081a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-06-23 10:09:55 +02:00 committed by Qt Cherry-pick Bot
parent 3458cf984a
commit 743aac16b3
2 changed files with 10 additions and 9 deletions

View File

@ -8,10 +8,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent)
: QFileSystemWatcherEngine(parent), : QFileSystemWatcherEngine(parent)
timer(this)
{ {
connect(&timer, SIGNAL(timeout()), SLOT(timeout()));
} }
QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths,
@ -43,7 +41,7 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths,
if ((!this->files.isEmpty() || if ((!this->files.isEmpty() ||
!this->directories.isEmpty()) && !this->directories.isEmpty()) &&
!timer.isActive()) { !timer.isActive()) {
timer.start(PollingInterval); timer.start(PollingInterval, this);
} }
return unhandled; return unhandled;
@ -72,8 +70,11 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path
return unhandled; return unhandled;
} }
void QPollingFileSystemWatcherEngine::timeout() void QPollingFileSystemWatcherEngine::timerEvent(QTimerEvent *e)
{ {
if (e->timerId() != timer.timerId())
return QFileSystemWatcherEngine::timerEvent(e);
for (auto it = files.begin(), end = files.end(); it != end; /*erasing*/) { for (auto it = files.begin(), end = files.end(); it != end; /*erasing*/) {
QString path = it.key(); QString path = it.key();
QFileInfo fi(path); QFileInfo fi(path);

View File

@ -15,11 +15,11 @@
// We mean it. // We mean it.
// //
#include <QtCore/qbasictimer.h>
#include <QtCore/qfileinfo.h> #include <QtCore/qfileinfo.h>
#include <QtCore/qmutex.h> #include <QtCore/qmutex.h>
#include <QtCore/qdatetime.h> #include <QtCore/qdatetime.h>
#include <QtCore/qdir.h> #include <QtCore/qdir.h>
#include <QtCore/qtimer.h>
#include <QtCore/qhash.h> #include <QtCore/qhash.h>
#include "qfilesystemwatcher_p.h" #include "qfilesystemwatcher_p.h"
@ -77,11 +77,11 @@ public:
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override; QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override; QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
private Q_SLOTS: private:
void timeout(); void timerEvent(QTimerEvent *) final;
private: private:
QTimer timer; QBasicTimer timer;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE