Skip to content

Commit

Permalink
QTimerEvent: add matches(const QBasicTimer &) convenience method
Browse files Browse the repository at this point in the history
Requested in code review.

Change-Id: If50f14db8c81890877677bb8c214d426b1dc1ad4
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
ahmadsamir committed Sep 20, 2024
1 parent f0052af commit 4593892
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/corelib/kernel/qcoreevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/corelib/kernel/qcoreevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef QCOREEVENT_H
#define QCOREEVENT_H

#include <QtCore/qbasictimer.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qobjectdefs.h>
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4593892

Please sign in to comment.