6.0.0-rc4Source

QChronoTimer Class

The QChronoTimer class provides repetitive and single-shot timers with intervals given as std::chrono durations. More…

Header#include <QChronoTimer>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since6.8
InheritsQObject

List of all members, including inherited members

Public Functions

QChronoTimer(QObject *parent = nullptr)
QChronoTimer(std::chrono::nanoseconds nsec, QObject *parent = nullptr)
~QChronoTimer()
voidsetInterval(std::chrono::nanoseconds nsec)
std::chrono::nanosecondsinterval() const
std::chrono::nanosecondsremainingTime() const
voidsetSingleShot(bool singleShot)
boolisSingleShot() const
voidsetTimerType(Qt::TimerType atype)
Qt::TimerTypetimerType() const
boolisActive() const
intid() const

Public Slots

voidstart()
voidstop()

Signals

voidtimeout()

Reimplemented Protected Functions

voidtimerEvent(QTimerEvent *event)

Detailed Description

A QChronoTimer is like QTimer, but its interval is a std::chrono::nanoseconds duration:

using namespace std::chrono_literals;
QChronoTimer timer(250ms);
QObject::connect(&timer, &QChronoTimer::timeout, [] { poll(); });
timer.start();

See also QTimer.

Differences from Qt

The event dispatcher of Nt works in milliseconds, so the interval is rounded up to whole milliseconds when the timer runs, and the timer type is recorded but does not change the precision. There is no singleShot() static function and no bindable properties.

Member Function Documentation

[explicit] QChronoTimer::QChronoTimer(QObject *parent = nullptr)

Constructs a timer with the given parent and an interval of 0. The timer is not started.

[explicit] QChronoTimer::QChronoTimer(std::chrono::nanoseconds nsec, QObject *parent = nullptr)

Constructs a timer with the interval nsec and the given parent. The timer is not started.

[override] QChronoTimer::~QChronoTimer()

Destroys the timer, stopping it if it is running.

int QChronoTimer::id() const

Returns the ID of the running timer, or 0 if it is not running.

std::chrono::nanoseconds QChronoTimer::interval() const

Returns the interval of the timer.

See also setInterval().

bool QChronoTimer::isActive() const

Returns true if the timer is running; otherwise returns false.

bool QChronoTimer::isSingleShot() const

Returns true if the timer times out only once; otherwise returns false.

std::chrono::nanoseconds QChronoTimer::remainingTime() const

Returns the time left until the timer times out, zero if it is overdue, or -1 nanosecond if it is not running.

void QChronoTimer::setInterval(std::chrono::nanoseconds nsec)

Sets the interval of the timer to nsec. If the timer is running, it is restarted with the new interval.

See also interval().

void QChronoTimer::setSingleShot(bool singleShot)

Sets whether the timer times out only once to singleShot.

See also isSingleShot().

void QChronoTimer::setTimerType(Qt::TimerType atype)

Sets the timer type to atype. It is recorded but does not change the precision in Nt.

[slot] void QChronoTimer::start()

Starts or restarts the timer with its interval.

See also stop() and timeout().

[slot] void QChronoTimer::stop()

Stops the timer.

See also start().

[signal] void QChronoTimer::timeout()

This signal is emitted when the timer times out.

See also interval() and start().

[override, protected] void QChronoTimer::timerEvent(QTimerEvent *event)

Reimplements QObject::timerEvent().

Qt::TimerType QChronoTimer::timerType() const

Returns the timer type.