![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qbasictimer.h>
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 |
Returns the timer's ID. | |
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 (std::chrono::milliseconds duration, QObject *obj) |
void | start (std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj) |
void | stop () |
Stops the timer. | |
Related Symbols | |
(Note that these are not member symbols.) | |
swap (QBasicTimer &lhs, QBasicTimer &rhs) | |
\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.
The \l{widgets/tetrix}{Tetrix} example uses QBasicTimer to control the rate at which pieces fall.
Definition at line 17 of file qbasictimer.h.
|
inlineconstexprnoexcept |
|
inline |
Destroys the basic timer.
Definition at line 24 of file qbasictimer.h.
|
inlinenoexcept |
Move-constructs a basic timer from other, which is left \l{isActive()}{inactive}.
Definition at line 26 of file qbasictimer.h.
References other().
|
inlinenoexcept |
Returns true
if the timer is running and has not been stopped; otherwise returns false
.
Definition at line 34 of file qbasictimer.h.
Referenced by QHeaderViewPrivate::doDelayedResizeSections(), QWaylandQuickShellEventFilter::eventFilter(), QHeaderViewPrivate::executePostedResize(), QQuickTextInputPrivate::handleFocusEvent(), QMenuSloppyState::hasParentActiveDelayTimer(), QTipLabel::hideTip(), QQuickPressHandler::isActive(), QWidgetTextControlPrivate::mousePressEvent(), QNmeaSatelliteInfoSourcePrivate::notifyNewUpdate(), QNmeaPositionInfoSourcePrivate::notifyNewUpdate(), QQC2::QWindowsStyle::polish(), QMacPanGestureRecognizer::recognize(), QUnifiedTimer::setTimingInterval(), QMenuPrivate::DelayState::start(), QMenuSloppyState::startTimerIfNotRunning(), QMacPanGestureRecognizer::timerEvent(), and QUnifiedTimer::updateAnimationTimers().
\obsolete Use chrono overload instead.
Referenced by QMenuBarPrivate::_q_internalShortcutActivated(), QComboBoxPrivate::adjustComboBoxSize(), QQuickFlickablePrivate::captureDelayedPress(), QAbstractItemViewPrivate::doDelayedItemsLayout(), QHeaderViewPrivate::doDelayedResizeSections(), QWaylandQuickShellEventFilter::eventFilter(), QTipLabel::hideTip(), QQuickViewPrivate::itemGeometryChanged(), QQuickWidgetPrivate::itemGeometryChanged(), QWidgetTextControlPrivate::mouseDoubleClickEvent(), QMenuPrivate::mouseEventTaken(), QQuickPressHandler::mousePressEvent(), QQC2::QWindowsStyle::polish(), QMacPanGestureRecognizer::recognize(), QTipLabel::restartExpireTimer(), QPulseAudioSink::resume(), QMainWindowLayout::setGeometry(), QMenuPrivate::DelayState::start(), QQuickToolTipPrivate::startDelay(), QQuickToolTipPrivate::startTimeout(), QMenuSloppyState::startTimer(), QNmeaPositionInfoSourcePrivate::startUpdates(), QNmeaSatelliteInfoSourcePrivate::startUpdates(), QWidgetTextControlPrivate::updateCursorBlinking(), and QQuickTextControlPrivate::updateCursorFlashTime().
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.
Use chrono overload instead.
Starts (or restarts) the timer with a duration timeout. The timer will be a Qt::CoarseTimer. See Qt::TimerType for information on the different timer types.
The given object will receive timer events.
Definition at line 129 of file qbasictimer.cpp.
References Qt::CoarseTimer.
void QBasicTimer::start | ( | std::chrono::milliseconds | duration, |
Qt::TimerType | timerType, | ||
QObject * | obj | ||
) |
Starts (or restarts) the timer with a duration timeout and the given timerType. See Qt::TimerType for information on the different timer types.
obj will receive timer events.
Definition at line 153 of file qbasictimer.cpp.
References QAbstractEventDispatcher::instance(), Q_UNLIKELY, qWarning, QAbstractEventDispatcher::registerTimer(), stop(), and QObject::thread().
void QBasicTimer::stop | ( | ) |
Stops the timer.
Definition at line 178 of file qbasictimer.cpp.
References QAbstractEventDispatcher::instance(), qWarning, QAbstractEventDispatcherPrivate::releaseTimerId(), and QAbstractEventDispatcher::unregisterTimer().
Referenced by QQuickTextInputPrivate::cancelPasswordEchoTimer(), QNetworkAccessCache::clear(), QTreeModel::clear(), QQuickFlickablePrivate::clearDelayedPress(), QTreeViewPrivate::collapse(), QTreeModel::ensureSorted(), QWaylandQuickShellEventFilter::eventFilter(), QAbstractItemViewPrivate::fetchMore(), QAbstractItemViewPrivate::interruptDelayedItemsLayout(), QMenuPrivate::mouseEventTaken(), QQuickPressHandler::mouseMoveEvent(), QWidgetTextControlPrivate::mousePressEvent(), QQuickPressHandler::mousePressEvent(), QQuickPressHandler::mouseReleaseEvent(), QMacPanGestureRecognizer::recognize(), QQuickFlickablePrivate::replayDelayedPress(), QMacPanGestureRecognizer::reset(), QHeaderViewPrivate::resizeSections(), QTipLabel::restartExpireTimer(), QMenuBarPrivate::setCurrentAction(), QMainWindowLayout::setGeometry(), QTreeModel::sort(), start(), QNmeaPositionInfoSourcePrivate::startUpdates(), QNmeaSatelliteInfoSourcePrivate::startUpdates(), QMenuPrivate::DelayState::stop(), QQuickToolTipPrivate::stopDelay(), QQuickToolTipPrivate::stopTimeout(), QMenuSloppyState::stopTimer(), QNmeaPositionInfoSourcePrivate::stopUpdates(), QNmeaSatelliteInfoSourcePrivate::stopUpdates(), QPulseAudioSink::suspend(), QTipLabel::timerEvent(), QMainWindowLayout::timerEvent(), QMacPanGestureRecognizer::timerEvent(), QQuickPressHandler::timerEvent(), QQuickTapHandler::timerEvent(), QQC2::QWindowsStyle::timerEvent(), QWaylandQuickShellEventFilter::timerEvent(), QComboBoxPrivateContainer::timerEvent(), QWidgetTextControlPrivate::updateCursorBlinking(), QQuickTextControlPrivate::updateCursorFlashTime(), and QQuickTapHandler::wantsEventPoint().
|
inlinenoexcept |
Swaps the timer other with this timer. This operation is very fast and never fails.
Definition at line 32 of file qbasictimer.h.
References other().
|
inlinenoexcept |
Returns the timer's ID.
Definition at line 35 of file qbasictimer.h.
Referenced by QMenuSloppyState::isTimerId(), QMacPanGestureRecognizer::recognize(), QUnifiedTimer::timerEvent(), QTreeModel::timerEvent(), QDefaultAnimationDriver::timerEvent(), QTipLabel::timerEvent(), QtPrivate::QCalendarTextNavigator::timerEvent(), QMainWindowLayout::timerEvent(), QMacPanGestureRecognizer::timerEvent(), QQuickTapHandler::timerEvent(), QQC2::QWindowsStyle::timerEvent(), QPulseAudioSink::timerEvent(), QWaylandQuickShellEventFilter::timerEvent(), and QComboBoxPrivateContainer::timerEvent().
|
related |
Swaps the timer lhs with rhs. This operation is very fast and never fails.
Definition at line 58 of file qbasictimer.h.
References swap().