QBasicTimer Class

QBasicTimer 类为对象提供定时器事件。更多

Header: #include <QBasicTimer>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

公共函数

QBasicTimer()
QBasicTimer(QBasicTimer &&other)
~QBasicTimer()
(since 6.8) Qt::TimerId id() const
bool isActive() const
(since 6.5) void start(std::chrono::milliseconds duration, QObject *object)
(since 6.5) void start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj)
void stop()
void swap(QBasicTimer &other)
QBasicTimer &operator=(QBasicTimer &&other)
void swap(QBasicTimer &lhs, QBasicTimer &rhs)

详细说明

这是一个快速、轻量级的低级类,由 Qt 内部使用。如果您想在应用程序中使用定时器,我们建议您使用更高级的QTimer 类而不是该类。请注意,该定时器是一个重复定时器,除非调用stop() 函数,否则它将发送后续的定时器事件。

要使用该类,请创建一个 QBasicTimer,并调用其 start() 函数,同时设置超时时间间隔和指向QObject 子类的指针。当定时器超时时,它会向QObject 子类发送一个定时器事件。定时器可随时通过stop() 停止。isActive() 返回true ,表示定时器正在运行;也就是说,定时器已经启动,没有达到超时时间,也没有被停止。定时器的 ID 可以使用 timerId() 进行检索。

该类对象不能复制,但可以移动,因此可以通过将它们保存在支持只可移动类型的容器(如 std::vector)中来维护基本定时器列表。

另请参阅 QTimer,QChronoTimer,QTimerEvent,QObject::timerEvent(),定时器仿射变换

成员函数文档

[constexpr noexcept] QBasicTimer::QBasicTimer()

构造一个基本计时器。

另请参见 start().

[noexcept] QBasicTimer::QBasicTimer(QBasicTimer &&other)

移动-从other 开始构建一个基本定时器,该定时器离开inactive

另请参阅 isActive() 和swap() 。

[noexcept] QBasicTimer::~QBasicTimer()

销毁基本计时器。

[noexcept, since 6.8] Qt::TimerId QBasicTimer::id() const

返回定时器的 ID。

此函数在 Qt 6.8 中引入。

另请参阅 QTimerEvent::id().

[noexcept] bool QBasicTimer::isActive() const

如果定时器正在运行且未停止,则返回true ;否则返回false

另请参阅 start() 和stop()。

[since 6.5] void QBasicTimer::start(std::chrono::milliseconds duration, QObject *object)

启动(或重启)计时器,超时时间为duration 。定时器将是Qt::CoarseTimer 。有关不同定时器类型的信息,请参阅Qt::TimerType

给定的object 将接收定时器事件。

此函数在 Qt 6.5 中引入。

另请参阅 stop(),isActive(),QObject::timerEvent() 和Qt::CoarseTimer

[since 6.5] void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj)

启动(或重启)计时器,超时时间为duration ,给定值为timerType 。有关不同定时器类型的信息,请参阅Qt::TimerType

obj 将接收定时器事件。

此函数在 Qt 6.5 中引入。

另请参阅 stop(),isActive(),QObject::timerEvent() 和Qt::TimerType

void QBasicTimer::stop()

停止计时器。

另请参阅 start() 和isActive() 。

[noexcept] void QBasicTimer::swap(QBasicTimer &other)

将该定时器与other 互换。这一操作非常快速,从未出现过故障。

[noexcept] QBasicTimer &QBasicTimer::operator=(QBasicTimer &&other)

移动 - 将other 分配给此基本计时器。other 保留为inactive

另请参阅 stop()、isActive() 和swap()。

相关非成员

[noexcept] void swap(QBasicTimer &lhs, QBasicTimer &rhs)

将定时器lhsrhs 互换。这一操作速度非常快,而且从未出现过故障。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.