185void QBasicTimer::start(Duration duration, Qt::TimerType timerType, QObject *obj)
187 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
188 if (duration < 0ns) {
189 qWarning(
"QBasicTimer::start: negative intervals aren't allowed; the "
190 "interval will be set to 1ms.");
193 if (Q_UNLIKELY(!eventDispatcher)) {
194 qWarning(
"QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
197 if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
198 qWarning(
"QBasicTimer::start: Timers cannot be started from another thread");
203 m_id = eventDispatcher->registerTimer(duration, timerType, obj);
211void QBasicTimer::stop()
214 QAbstractEventDispatcher *eventDispatcher =
nullptr;
217 if (QThreadData *data = QThreadData::currentThreadData())
218 eventDispatcher = data->eventDispatcher.loadRelaxed();
220 if (eventDispatcher && !eventDispatcher->unregisterTimer(m_id)) {
221 qWarning(
"QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
224 QAbstractEventDispatcherPrivate::releaseTimerId(m_id);
226 m_id = Qt::TimerId::Invalid;