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
qfuturewatcher.h
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#ifndef QFUTUREWATCHER_H
5#define QFUTUREWATCHER_H
6
7#include <QtCore/qfuture.h>
8#include <QtCore/qobject.h>
9
11
13
14
15class QEvent;
16
18class Q_CORE_EXPORT QFutureWatcherBase : public QObject
19{
21 Q_DECLARE_PRIVATE(QFutureWatcherBase)
22
23public:
24 explicit QFutureWatcherBase(QObject *parent = nullptr);
25 // de-inline dtor
26
27 int progressValue() const;
28 int progressMinimum() const;
29 int progressMaximum() const;
30 QString progressText() const;
31
32 bool isStarted() const;
33 bool isFinished() const;
34 bool isRunning() const;
35 bool isCanceled() const;
36#if QT_DEPRECATED_SINCE(6, 0)
37 QT_DEPRECATED_VERSION_X_6_0("Use isSuspending() or isSuspended() instead.")
38 bool isPaused() const;
39#endif
40 bool isSuspending() const;
41 bool isSuspended() const;
42
43 void waitForFinished();
44
45 void setPendingResultsLimit(int limit);
46
47 bool event(QEvent *event) override;
48
50 void started();
51 void finished();
52 void canceled();
53#if QT_DEPRECATED_SINCE(6, 0)
54 QT_DEPRECATED_VERSION_X_6_0("Use suspending() instead.")
55 void paused();
56#endif
57 void suspending();
58 void suspended();
59 void resumed();
60 void resultReadyAt(int resultIndex);
61 void resultsReadyAt(int beginIndex, int endIndex);
62 void progressRangeChanged(int minimum, int maximum);
63 void progressValueChanged(int progressValue);
64 void progressTextChanged(const QString &progressText);
65
66public Q_SLOTS:
67 void cancel();
68 void setSuspended(bool suspend);
69 void suspend();
70 void resume();
71 void toggleSuspended();
72
73#if QT_DEPRECATED_SINCE(6, 0)
74 QT_DEPRECATED_VERSION_X_6_0("Use setSuspended() instead.")
75 void setPaused(bool paused);
76
77 QT_DEPRECATED_VERSION_X_6_0("Use suspended() instead.")
78 void pause();
79
80 QT_DEPRECATED_VERSION_X_6_0("Use toggleSuspended() instead.")
81 void togglePaused();
82#endif
83
84protected:
85 void connectNotify (const QMetaMethod &signal) override;
86 void disconnectNotify (const QMetaMethod &signal) override;
87
88 // called from setFuture() implemented in template sub-classes
89 void connectOutputInterface();
90 void disconnectOutputInterface(bool pendingAssignment = false);
91
92private:
93 // implemented in the template sub-classes
94 virtual const QFutureInterfaceBase &futureInterface() const = 0;
96};
97
98template <typename T>
100{
101public:
102 explicit QFutureWatcher(QObject *_parent = nullptr)
103 : QFutureWatcherBase(_parent)
104 { }
107
108 void setFuture(const QFuture<T> &future);
109 QFuture<T> future() const
110 { return m_future; }
111
112 template<typename U = T, typename = QtPrivate::EnableForNonVoid<U>>
113 T result() const { return m_future.result(); }
114
115 template<typename U = T, typename = QtPrivate::EnableForNonVoid<U>>
116 T resultAt(int index) const { return m_future.resultAt(index); }
117
118#ifdef Q_QDOC
119 int progressValue() const;
120 int progressMinimum() const;
121 int progressMaximum() const;
122 QString progressText() const;
123
124 bool isStarted() const;
125 bool isFinished() const;
126 bool isRunning() const;
127 bool isCanceled() const;
128#if QT_DEPRECATED_SINCE(6, 0)
129 bool isPaused() const;
130#endif
131 bool isSuspending() const;
132 bool isSuspended() const;
133
134 void waitForFinished();
135
137
139 void started();
140 void finished();
141 void canceled();
142#if QT_DEPRECATED_SINCE(6, 0)
143 void paused();
144#endif
145 void suspending();
146 void suspended();
147 void resumed();
148 void resultReadyAt(int resultIndex);
149 void resultsReadyAt(int beginIndex, int endIndex);
150 void progressRangeChanged(int minimum, int maximum);
153
154public Q_SLOTS:
155 void cancel();
156 void setSuspended(bool suspend);
157 void suspend();
158 void resume();
159 void toggleSuspended();
160#if QT_DEPRECATED_SINCE(6, 0)
161 void setPaused(bool paused);
162 void pause();
163 void togglePaused();
164#endif // QT_DEPRECATED_SINCE(6, 0)
165
166#endif // Q_QDOC
167
168private:
169 QFuture<T> m_future;
170 const QFutureInterfaceBase &futureInterface() const override { return m_future.d; }
171 QFutureInterfaceBase &futureInterface() override { return m_future.d; }
172};
173
174template <typename T>
175Q_INLINE_TEMPLATE void QFutureWatcher<T>::setFuture(const QFuture<T> &_future)
176{
177 if (_future.d == m_future.d)
178 return;
179
180 disconnectOutputInterface(true);
181 m_future = _future;
182 connectOutputInterface();
183}
184
186
187#endif // QFUTUREWATCHER_H
\inmodule QtCore
Definition qcoreevent.h:45
void resultsReadyAt(int beginIndex, int endIndex)
bool isSuspending() const
virtual const QFutureInterfaceBase & futureInterface() const =0
void progressValueChanged(int progressValue)
void setPendingResultsLimit(int limit)
void progressRangeChanged(int minimum, int maximum)
int progressMaximum() const
void setSuspended(bool suspend)
void progressTextChanged(const QString &progressText)
void disconnectOutputInterface(bool pendingAssignment=false)
virtual QFutureInterfaceBase & futureInterface()=0
int progressMinimum() const
QString progressText() const
void resultReadyAt(int resultIndex)
void setFuture(const QFuture< T > &future)
Starts watching the given future.
QFuture< T > future() const
Returns the watched future.
const QFutureInterfaceBase & futureInterface() const override
QFutureWatcher(QObject *_parent=nullptr)
Constructs a new QFutureWatcher with the given parent.
~QFutureWatcher()
Destroys the QFutureWatcher.
QFutureInterfaceBase & futureInterface() override
T resultAt(int index) const
\inmodule QtCore
Definition qmetaobject.h:19
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
auto signal
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
GLuint index
[2]
struct _cl_event * event
GLint limit
static bool isRunning()
Definition main.cpp:452
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_0(text)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
QFuture< void > future
[5]
future cancel()
future resume()
future suspend()
future waitForFinished()