Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QBasicTimer Class Reference

\inmodule QtCore More...

#include <qbasictimer.h>

Collaboration diagram for QBasicTimer:

Public Types

using Duration = QAbstractEventDispatcher::Duration
 A {std::chrono::duration} type that is used in various API in this class.

Public Member Functions

constexpr QBasicTimer () noexcept
 Constructs a basic timer.
 ~QBasicTimer ()
 Destroys the basic timer.
 QBasicTimer (QBasicTimer &&other) noexcept
void swap (QBasicTimer &other) noexcept
bool isActive () const noexcept
 Returns true if the timer is running and has not been stopped; otherwise returns false.
int timerId () const noexcept
 \obsolete
Qt::TimerId id () const noexcept
void start (int msec, QObject *obj)
 \obsolete Use chrono overload instead.
void start (int msec, Qt::TimerType timerType, QObject *obj)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. \obsolete.
void start (Duration duration, QObject *obj)
void start (Duration duration, Qt::TimerType timerType, QObject *obj)
void stop ()
 Stops the timer.

(Note that these are not member symbols.)

 swap (QBasicTimer &lhs, QBasicTimer &rhs)

Detailed Description

\inmodule QtCore

The QBasicTimer class provides timer events for objects.

This is a fast, lightweight, and low-level class used by Qt internally. We recommend using the higher-level QTimer class rather than this class if you want to use timers in your applications. Note that this timer is a repeating timer that will send subsequent timer events unless the stop() function is called.

To use this class, create a QBasicTimer, and call its start() function with a timeout interval and with a pointer to a QObject subclass. When the timer times out it will send a timer event to the QObject subclass. The timer can be stopped at any time using stop(). isActive() returns true for a timer that is running; i.e. it has been started, has not reached the timeout time, and has not been stopped. The timer's ID can be retrieved using timerId().

Objects of this class cannot be copied, but can be moved, so you can maintain a list of basic timers by holding them in container that supports move-only types, e.g. std::vector.

See also
QTimer, QChronoTimer, QTimerEvent, QObject::timerEvent(), Timers, {Affine Transformations}

Definition at line 18 of file qbasictimer.h.

Member Typedef Documentation

◆ Duration

A {std::chrono::duration} type that is used in various API in this class.

This type exists to facilitate a possible transition to a higher or lower granularity.

In all current platforms, it is nanoseconds.

Definition at line 25 of file qbasictimer.h.

Constructor & Destructor Documentation

◆ QBasicTimer() [1/2]

QBasicTimer::QBasicTimer ( )
inlineconstexprnoexcept

Constructs a basic timer.

See also
start()

Definition at line 27 of file qbasictimer.h.

◆ ~QBasicTimer()

QBasicTimer::~QBasicTimer ( )
inline

Destroys the basic timer.

Definition at line 28 of file qbasictimer.h.

◆ QBasicTimer() [2/2]

QBasicTimer::QBasicTimer ( QBasicTimer && other)
inlinenoexcept
Since
5.14

Move-constructs a basic timer from other, which is left \l{isActive()}{inactive}.

See also
isActive(), swap()

Definition at line 30 of file qbasictimer.h.

Member Function Documentation

◆ id()

Qt::TimerId QBasicTimer::id ( ) const
inlinenoexcept
Since
6.8

Returns the timer's ID.

See also
QTimerEvent::id()

Definition at line 40 of file qbasictimer.h.

◆ isActive()

bool QBasicTimer::isActive ( ) const
inlinenoexcept

Returns true if the timer is running and has not been stopped; otherwise returns false.

See also
start(), stop()

Definition at line 38 of file qbasictimer.h.

◆ start() [1/4]

void QBasicTimer::start ( Duration duration,
QObject * obj )
inline

Definition at line 50 of file qbasictimer.h.

◆ start() [2/4]

void QBasicTimer::start ( Duration duration,
Qt::TimerType timerType,
QObject * obj )
Since
6.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Starts (or restarts) the timer with a duration timeout and the given timerType. See Qt::TimerType for information on the different timer types.

negative-intervals-not-allowed

obj will receive timer events.

start-nanoseconds-note

See also
stop(), isActive(), QObject::timerEvent(), Qt::TimerType

Definition at line 185 of file qbasictimer.cpp.

◆ start() [3/4]

void QBasicTimer::start ( int msec,
QObject * obj )

\obsolete Use chrono overload instead.

◆ start() [4/4]

void QBasicTimer::start ( int msec,
Qt::TimerType timerType,
QObject * obj )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. \obsolete.

\fn void QBasicTimer::start(Duration duration, QObject *object)
\since 6.5

Starts (or restarts) the timer with a \a duration timeout. The
timer will be a Qt::CoarseTimer. See Qt::TimerType for information on the
different timer types.

The given \a object will receive timer events.

\include timers-common.qdocinc negative-intervals-not-allowed

! [start-nanoseconds-note]

Note
Starting from Qt 6.9 this method takes std::chrono::nanoseconds, before that it took std::chrono::milliseconds. This change is backwards compatible. ! [start-nanoseconds-note]
\sa stop(), isActive(), QObject::timerEvent(), Qt::CoarseTimer

Use chrono overload instead.

◆ stop()

void QBasicTimer::stop ( )

Stops the timer.

See also
start(), isActive()

Definition at line 211 of file qbasictimer.cpp.

◆ swap()

void QBasicTimer::swap ( QBasicTimer & other)
inlinenoexcept
Since
5.14 \memberswap{timer}

Definition at line 36 of file qbasictimer.h.

◆ timerId()

int QBasicTimer::timerId ( ) const
inlinenoexcept

\obsolete

Returns the timer's ID.

In new code use id() instead.

See also
QTimerEvent::timerId()

Definition at line 39 of file qbasictimer.h.

◆ swap()

swap ( QBasicTimer & lhs,
QBasicTimer & rhs )
related
Since
5.14

Swaps the timer lhs with rhs. This operation is very fast and never fails.

Definition at line 69 of file qbasictimer.h.


The documentation for this class was generated from the following files: