diff options
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
| -rw-r--r-- | src/corelib/kernel/qobject.cpp | 80 |
1 files changed, 33 insertions, 47 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 34c9e52f637..d3dead9d8f1 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1777,13 +1777,35 @@ void QObjectPrivate::_q_reregisterTimers(void *pointer) // /*! + \fn int QObject::startTimer(int interval, Qt::TimerType timerType) + + This is an overloaded function that will start a timer of type + \a timerType and a timeout of \a interval milliseconds. This is + equivalent to calling: + \code + startTimer(std::chrono::milliseconds{interval}, timerType); + \endcode + + \sa timerEvent(), killTimer(), QTimer::singleShot() +*/ + +int QObject::startTimer(int interval, Qt::TimerType timerType) +{ + return startTimer(std::chrono::milliseconds{interval}, timerType); +} + +/*! + \since 5.9 + \overload + \fn int QObject::startTimer(std::chrono::milliseconds interval, Qt::TimerType timerType) + Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. - A timer event will occur every \a interval milliseconds until - killTimer() is called. If \a interval is 0, then the timer event - occurs once every time there are no more window system events to - process. + A timer event will occur every \a interval until killTimer() + is called. If \a interval is equal to \c{std::chrono::duration::zero()}, + then the timer event occurs once every time there are no more window + system events to process. The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this @@ -1810,12 +1832,13 @@ void QObjectPrivate::_q_reregisterTimers(void *pointer) \sa timerEvent(), killTimer(), QTimer::singleShot() */ - -int QObject::startTimer(int interval, Qt::TimerType timerType) +int QObject::startTimer(std::chrono::milliseconds interval, Qt::TimerType timerType) { Q_D(QObject); - if (Q_UNLIKELY(interval < 0)) { + using namespace std::chrono_literals; + + if (Q_UNLIKELY(interval < 0ms)) { qWarning("QObject::startTimer: Timers cannot have negative intervals"); return 0; } @@ -1829,52 +1852,15 @@ int QObject::startTimer(int interval, Qt::TimerType timerType) qWarning("QObject::startTimer: Timers cannot be started from another thread"); return 0; } - int timerId = thisThreadData->eventDispatcher.loadRelaxed()->registerTimer(interval, timerType, this); + + auto dispatcher = thisThreadData->eventDispatcher.loadRelaxed(); + int timerId = dispatcher->registerTimer(interval.count(), timerType, this); d->ensureExtraData(); d->extraData->runningTimers.append(timerId); return timerId; } /*! - \since 5.9 - \overload - \fn int QObject::startTimer(std::chrono::milliseconds time, Qt::TimerType timerType) - - Starts a timer and returns a timer identifier, or returns zero if - it could not start a timer. - - A timer event will occur every \a time interval until killTimer() - is called. If \a time is equal to \c{std::chrono::duration::zero()}, - then the timer event occurs once every time there are no more window - system events to process. - - The virtual timerEvent() function is called with the QTimerEvent - event parameter class when a timer event occurs. Reimplement this - function to get timer events. - - If multiple timers are running, the QTimerEvent::timerId() can be - used to find out which timer was activated. - - Example: - - \snippet code/src_corelib_kernel_qobject.cpp 8 - - Note that QTimer's accuracy depends on the underlying operating system and - hardware. The \a timerType argument allows you to customize the accuracy of - the timer. See Qt::TimerType for information on the different timer types. - Most platforms support an accuracy of 20 milliseconds; some provide more. - If Qt is unable to deliver the requested number of timer events, it will - silently discard some. - - The QTimer class provides a high-level programming interface with - single-shot timers and timer signals instead of events. There is - also a QBasicTimer class that is more lightweight than QTimer and - less clumsy than using timer IDs directly. - - \sa timerEvent(), killTimer(), QTimer::singleShot() -*/ - -/*! Kills the timer with timer identifier, \a id. The timer identifier is returned by startTimer() when a timer |
