summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtimer.h
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-02-16 16:46:12 +0200
committerAhmad Samir <a.samirh78@gmail.com>2024-03-02 03:31:40 +0200
commita4a679ee796a476048ddee3f88025035cca3631a (patch)
tree177c8500aca76b378b0bf83bc2b5100a24693e7b /src/corelib/kernel/qtimer.h
parent56e151663ebfd4fc0876d33f22c81f0218339914 (diff)
QTimer: delegate more to the chrono overloads
singleShot() (static) methods: QSingleShotTimer's interval isn't limited by the `int` interval in QTimer, so this is OK, no narrowing. start(int)/setInterval(int): Techincally it makes no difference which overloads delegate to which, because QTimer stores the interval in an `int` (QProperty); so any {int interval,chrono::milliseconds.count()} > INT_MAX is narrowing anyway. But it's less confusing and matches what has been done in other classes when porting them to chrono, int overload delegates to chrono overload. Change-Id: I5ae0888f16130ae28a74be4498a180485fa34550 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qtimer.h')
-rw-r--r--src/corelib/kernel/qtimer.h44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index 80802a4cc5..9b59895e60 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -46,7 +46,10 @@ public:
bool isSingleShot() const;
QBindable<bool> bindableSingleShot();
+ QT_CORE_INLINE_SINCE(6, 8)
static void singleShot(int msec, const QObject *receiver, const char *member);
+
+ QT_CORE_INLINE_SINCE(6, 8)
static void singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member);
// singleShot with context
@@ -111,10 +114,7 @@ Q_SIGNALS:
void timeout(QPrivateSignal);
public:
- void setInterval(std::chrono::milliseconds value)
- {
- setInterval(int(value.count()));
- }
+ void setInterval(std::chrono::milliseconds value);
std::chrono::milliseconds intervalAsDuration() const
{
@@ -128,18 +128,12 @@ public:
static void singleShot(std::chrono::milliseconds value, const QObject *receiver, const char *member)
{
- singleShot(int(value.count()), receiver, member);
- }
-
- static void singleShot(std::chrono::milliseconds value, Qt::TimerType timerType, const QObject *receiver, const char *member)
- {
- singleShot(int(value.count()), timerType, receiver, member);
+ singleShot(value, defaultTypeFor(value), receiver, member);
}
+ static void singleShot(std::chrono::milliseconds interval, Qt::TimerType timerType,
+ const QObject *receiver, const char *member);
- void start(std::chrono::milliseconds value)
- {
- start(int(value.count()));
- }
+ void start(std::chrono::milliseconds value);
protected:
void timerEvent(QTimerEvent *) override;
@@ -163,17 +157,29 @@ private:
return interval >= 2s ? Qt::CoarseTimer : Qt::PreciseTimer;
}
+ QT_CORE_INLINE_SINCE(6, 8)
static void singleShotImpl(int msec, Qt::TimerType timerType,
const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj);
static void singleShotImpl(std::chrono::milliseconds interval, Qt::TimerType timerType,
- const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj)
- {
- singleShotImpl(int(interval.count()),
- timerType, receiver, slotObj);
- }
+ const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj);
};
+#if QT_CORE_INLINE_IMPL_SINCE(6, 8)
+void QTimer::singleShot(int msec, const QObject *receiver, const char *member)
+{ singleShot(std::chrono::milliseconds{msec}, receiver, member); }
+
+void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiver,
+ const char *member)
+{ singleShot(std::chrono::milliseconds{msec}, timerType, receiver, member); }
+
+void QTimer::singleShotImpl(int msec, Qt::TimerType timerType,
+ const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj)
+{
+ singleShotImpl(std::chrono::milliseconds{msec}, timerType, receiver, slotObj);
+}
+#endif
+
QT_END_NAMESPACE
#endif // QT_NO_QOBJECT