Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qbasictimer.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qbasictimer.h"
7
9
129void QBasicTimer::start(std::chrono::milliseconds duration, QObject *object)
130{
131 start(duration, Qt::CoarseTimer, object);
132}
133
153void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj)
154{
156 if (Q_UNLIKELY(duration.count() < 0)) {
157 qWarning("QBasicTimer::start: Timers cannot have negative timeouts");
158 return;
159 }
160 if (Q_UNLIKELY(!eventDispatcher)) {
161 qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
162 return;
163 }
164 if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
165 qWarning("QBasicTimer::start: Timers cannot be started from another thread");
166 return;
167 }
168 stop();
169 if (obj)
170 id = eventDispatcher->registerTimer(duration.count(), timerType, obj);
171}
172
179{
180 if (id) {
182 if (eventDispatcher && !eventDispatcher->unregisterTimer(id)) {
183 qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
184 return;
185 }
187 }
188 id = 0;
189}
190
static QAbstractEventDispatcher * instance(QThread *thread=nullptr)
Returns a pointer to the event dispatcher object for the specified thread.
virtual bool unregisterTimer(int timerId)=0
Unregisters the timer with the given timerId.
int registerTimer(qint64 interval, Qt::TimerType timerType, QObject *object)
Registers a timer with the specified interval and timerType for the given object and returns the time...
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
\inmodule QtCore
Definition qobject.h:90
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1561
Combined button and popup list for selecting options.
TimerType
@ CoarseTimer
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:162
GLuint start
GLhandleARB obj
[2]