diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 1623855d95a..abe4f9bbbaa 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -566,6 +566,14 @@ Q_IMPL_EVENT_COMMON(QTimerEvent) Qt::TimerId. */ +/*! + \fn QTimerEvent::matches(const QBasicTimer &timer) const + \since 6.9 + + Returns \c true if this timer event and \a timer have the same ID, + otherwise returns \c false. +*/ + /*! \class QChildEvent \inmodule QtCore diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index ae512a99b43..1f27da6cce5 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -4,6 +4,7 @@ #ifndef QCOREEVENT_H #define QCOREEVENT_H +#include #include #include #include @@ -371,6 +372,8 @@ class Q_CORE_EXPORT QTimerEvent : public QEvent int timerId() const { return qToUnderlying(id()); } Qt::TimerId id() const { return m_id; } + bool matches(const QBasicTimer &timer) const noexcept + { return m_id == timer.id(); } protected: Qt::TimerId m_id; diff --git a/tests/auto/corelib/kernel/qchronotimer/tst_qchronotimer.cpp b/tests/auto/corelib/kernel/qchronotimer/tst_qchronotimer.cpp index e963b1f018d..18b2c31331d 100644 --- a/tests/auto/corelib/kernel/qchronotimer/tst_qchronotimer.cpp +++ b/tests/auto/corelib/kernel/qchronotimer/tst_qchronotimer.cpp @@ -696,7 +696,7 @@ class RestartedTimerFiresTooSoonObject : public QObject void timerEvent(QTimerEvent* ev) override { - if (ev->timerId() != m_timer.timerId()) + if (!ev->matches(m_timer)) return; m_timer.stop();