70 QFutureIterator<QString>
i(
future);
72 while (
i.hasPrevious())
77 using NetworkReply = std::variant<QByteArray, QNetworkReply::NetworkError>;
80 using IOResult = std::variant<QString, IOError>;
88 if (
auto error = std::get_if<QNetworkReply::NetworkError>(&
reply))
91 auto data = std::get_if<QByteArray>(&
reply);
97 if (
auto filePath = std::get_if<QString>(&
result)) {
118 auto continuation =
future.then([](
int res1){ ... }).then([](
int res2){ ... })...
122 auto result = continuation.result();
130 auto resultFuture =
future.then([](
int res) {
134 }).onFailed([](
const Error &
e) {
144 auto result = resultFuture.result();
151 throw std::runtime_error(
"message");
153 }).onFailed([](
const std::exception &
e) {
155 }).onFailed([](
const std::runtime_error &
e) {
162 auto resultFuture =
future.then([](
int res) {
164 throw Error(
"message");
166 }).onFailed([](
const std::exception &
e) {
173 auto result = resultFuture.result();
186 void singleArgSignal(
int value);
187 void multipleArgs(
int value1,
double value2,
const QString &value3);
193 QFuture<void> voidFuture = QtFuture::connect(&
object, &Object::noArgSignal);
194 QFuture<int> intFuture = QtFuture::connect(&
object, &Object::singleArgSignal);
196 using Args = std::tuple<int, double, QString>;
197 QFuture<Args> tupleFuture = QtFuture::connect(&
object, &Object::multipleArgs)
201 QtFuture::connect(&
object, &Object::singleArgSignal).then([](
int value) {
213 QtFuture::connect(&
object, &Object::singleArgSignal).then([](
int value) {
215 throw std::exception();
217 }).onFailed([](
const std::exception &
e) {
226 auto resultFuture = testFuture.
then([](
int res) {
243 auto resultFuture = testFuture.
then([](
int res) {
281 throw std::exception();
282 }).onFailed(
this, [] {
289 auto future = cachedResultsReady ? QtFuture::makeReadyFuture(
results)
300 auto resultFuture = testFuture.
then([](
int res) {
304 }).then([](
int res) {
323 QtFuture::whenAll<std::vector<QFuture<int>>>(inputFutures.begin(), inputFutures.end());
353 QtFuture::whenAll<std::vector<FuturesVariant>>(intFuture, stringFuture, voidFuture);
The QException class provides a base class for exceptions that can be transferred across threads.
QFuture< ResultType< Function > > then(Function &&function)
The QObject class is the base class of all Qt objects.
The QString class provides a Unicode character string.
auto run(QThreadPool *pool, Function &&f, Args &&...args)
QFuture< WhenAnyResult< typename QtPrivate::Future< ValueType >::type > > whenAny(InputIt first, InputIt last)
QFuture< OutputSequence > whenAll(InputIt first, InputIt last)
QTextStream & endl(QTextStream &stream)
EGLOutputLayerEXT EGLint EGLAttrib value
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QUrl url("http://www.example.com/List of holidays.xml")
[0]
std::variant< QString, IOError > IOResult
std::variant< QByteArray, QNetworkReply::NetworkError > NetworkReply
[2]
QFuture< QString > future
[0]
QFuture< QString >::const_iterator i