本文整理汇总了C++中Future::result方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::result方法的具体用法?C++ Future::result怎么用?C++ Future::result使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::result方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: futureWatcher
void futureWatcher()
{
std::mutex mutex;
mutex.lock();
Future<int> future = async(std::launch::async, [&mutex](Notifier notifier)
{
notifier.status("asdf");
notifier.progress(1, 100);
mutex.lock();
mutex.unlock();
notifier.progress(99, 100);
notifier.status("fdsa");
return 42;
});
FutureWatcher<int> watcher(future);
QSignalSpy started(&watcher, SIGNAL(started()));
QSignalSpy finished(&watcher, SIGNAL(finished()));
QSignalSpy canceled(&watcher, SIGNAL(canceled()));
QSignalSpy exception(&watcher, SIGNAL(exception()));
QSignalSpy progress(&watcher, SIGNAL(progress(std::size_t, std::size_t)));
QSignalSpy status(&watcher, SIGNAL(status(QString)));
future.start();
std::this_thread::sleep_for(1ms);
QCOMPARE(started.size(), 1);
QVERIFY(started.first().isEmpty());
QVERIFY(finished.isEmpty());
QVERIFY(canceled.isEmpty());
QVERIFY(exception.isEmpty());
QCOMPARE(progress.size(), 1);
QCOMPARE(progress.first(), QList<QVariant>() << 1 << 100);
QCOMPARE(status.size(), 1);
QCOMPARE(status.first(), QList<QVariant>() << "asdf");
mutex.unlock();
future.result();
QCOMPARE(started.size(), 1); // stays the same
QVERIFY(started.first().isEmpty()); // stays the same
QCOMPARE(finished.size(), 1); // incremented
QVERIFY(finished.first().isEmpty());
QVERIFY(canceled.isEmpty()); // stays the same
QVERIFY(exception.isEmpty()); // stays the same
QCOMPARE(progress.size(), 2);
QCOMPARE(progress.at(0), QList<QVariant>() << 1 << 100);
QCOMPARE(progress.at(1), QList<QVariant>() << 99 << 100);
QCOMPARE(status.size(), 2);
QCOMPARE(status.at(0), QList<QVariant>() << "asdf");
QCOMPARE(status.at(1), QList<QVariant>() << "fdsa");
}