Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qchronotimer.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#ifndef QCHRONOTIMER_H
6#define QCHRONOTIMER_H
7
8#ifndef QT_NO_QOBJECT
9
10#include <QtCore/qcoreevent.h>
11#include <QtCore/qnamespace.h>
12#include <QtCore/qobject.h>
13#include <QtCore/qproperty.h>
14#include <QtCore/qtimer.h>
15
16#include <chrono>
17
18QT_BEGIN_NAMESPACE
19
20class QTimerPrivate;
21class Q_CORE_EXPORT QChronoTimer : public QObject
22{
23 Q_OBJECT
24 Q_PROPERTY(bool singleShot READ isSingleShot WRITE setSingleShot
25 BINDABLE bindableSingleShot FINAL)
26 Q_PROPERTY(std::chrono::nanoseconds interval READ interval WRITE setInterval
27 BINDABLE bindableInterval FINAL)
28 Q_PROPERTY(std::chrono::nanoseconds remainingTime READ remainingTime FINAL)
29 Q_PROPERTY(Qt::TimerType timerType READ timerType WRITE setTimerType
30 BINDABLE bindableTimerType FINAL)
31 Q_PROPERTY(bool active READ isActive STORED false BINDABLE bindableActive FINAL)
32
33 template <typename Functor>
34 using FunctorContext = typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType;
35
36public:
37 explicit QChronoTimer(std::chrono::nanoseconds nsec, QObject *parent = nullptr);
38 explicit QChronoTimer(QObject *parent = nullptr);
39 ~QChronoTimer() override;
40
41 bool isActive() const;
42 QBindable<bool> bindableActive();
43 Qt::TimerId id() const;
44
45 void setInterval(std::chrono::nanoseconds nsec);
46 std::chrono::nanoseconds interval() const;
47 QBindable<std::chrono::nanoseconds> bindableInterval();
48
49 std::chrono::nanoseconds remainingTime() const;
50
51 void setTimerType(Qt::TimerType atype);
52 Qt::TimerType timerType() const;
53 QBindable<Qt::TimerType> bindableTimerType();
54
55 void setSingleShot(bool singleShot);
56 bool isSingleShot() const;
57 QBindable<bool> bindableSingleShot();
58
59#ifdef Q_QDOC
60 template <typename Functor>
61 QMetaObject::Connection callOnTimeout(const QObject *context, Functor &&slot,
62 Qt::ConnectionType connectionType = Qt::AutoConnection);
63#else
64 template <typename ... Args>
65 QMetaObject::Connection callOnTimeout(Args && ...args)
66 {
67 return QObject::connect(this, &QChronoTimer::timeout, std::forward<Args>(args)... );
68 }
69#endif
70
71public Q_SLOTS:
72 void start();
73 void stop();
74
75Q_SIGNALS:
76 void timeout(QPrivateSignal);
77
78protected:
79 void timerEvent(QTimerEvent *) override;
80
81private:
82 Q_DISABLE_COPY(QChronoTimer)
83
84 // QChronoTimer uses QTimerPrivate
85 inline QTimerPrivate *d_func() noexcept
86 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<QTimerPrivate *>(qGetPtrHelper(d_ptr));) }
87 inline const QTimerPrivate *d_func() const noexcept
88 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const QTimerPrivate *>(qGetPtrHelper(d_ptr));) }
89
90 // These two functions are inherited from QObject
91 int startTimer(std::chrono::nanoseconds) = delete;
92 void killTimer(int) = delete;
93};
94
95QT_END_NAMESPACE
96
97#endif // QT_NO_QOBJECT
98
99#endif // QCHRONOTIMER_H
\inmodule QtCore