Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
127void QBasicTimer::start(std::chrono::milliseconds duration, QObject *object)
128{
129 start(duration, Qt::CoarseTimer, object);
130}
131
151void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj)
152{
154 if (Q_UNLIKELY(duration.count() < 0)) {
155 qWarning("QBasicTimer::start: Timers cannot have negative timeouts");
156 return;
157 }
158 if (Q_UNLIKELY(!eventDispatcher)) {
159 qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
160 return;
161 }
162 if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
163 qWarning("QBasicTimer::start: Timers cannot be started from another thread");
164 return;
165 }
166 stop();
167 if (obj)
168 id = int(eventDispatcher->registerTimer(duration, timerType, obj));
169}
170
177{
178 if (id) {
180 if (eventDispatcher && !eventDispatcher->unregisterTimer(Qt::TimerId(id))) {
181 qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
182 return;
183 }
185 }
186 id = 0;
187}
188
static QAbstractEventDispatcher * instance(QThread *thread=nullptr)
Returns a pointer to the event dispatcher object for the specified thread.
virtual bool unregisterTimer(Qt::TimerId timerId)=0
Qt::TimerId registerTimer(Duration interval, Qt::TimerType timerType, QObject *object)
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
\inmodule QtCore
Definition qobject.h:103
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1598
Combined button and popup list for selecting options.
TimerType
@ CoarseTimer
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:166
GLuint start
GLhandleARB obj
[2]