From 743aac16b370e1d894dedb19d250cc4f65c0a402 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 Jun 2023 10:09:55 +0200 Subject: [PATCH] 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 (cherry picked from commit 22858ffcedda16cd9f773df9ec74a5bff72a081a) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemwatcher_polling.cpp | 11 ++++++----- src/corelib/io/qfilesystemwatcher_polling_p.h | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index 03425ac212d..6ec8b17ea45 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -8,10 +8,8 @@ QT_BEGIN_NAMESPACE QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine(QObject *parent) - : QFileSystemWatcherEngine(parent), - timer(this) + : QFileSystemWatcherEngine(parent) { - connect(&timer, SIGNAL(timeout()), SLOT(timeout())); } QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, @@ -43,7 +41,7 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, if ((!this->files.isEmpty() || !this->directories.isEmpty()) && !timer.isActive()) { - timer.start(PollingInterval); + timer.start(PollingInterval, this); } return unhandled; @@ -72,8 +70,11 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path 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*/) { QString path = it.key(); QFileInfo fi(path); diff --git a/src/corelib/io/qfilesystemwatcher_polling_p.h b/src/corelib/io/qfilesystemwatcher_polling_p.h index 2d7423b39d6..b1100b061a1 100644 --- a/src/corelib/io/qfilesystemwatcher_polling_p.h +++ b/src/corelib/io/qfilesystemwatcher_polling_p.h @@ -15,11 +15,11 @@ // We mean it. // +#include #include #include #include #include -#include #include #include "qfilesystemwatcher_p.h" @@ -77,11 +77,11 @@ public: QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override; QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override; -private Q_SLOTS: - void timeout(); +private: + void timerEvent(QTimerEvent *) final; private: - QTimer timer; + QBasicTimer timer; }; QT_END_NAMESPACE