C++ QT并发阻塞MappedReduced v.s MappedReduced
根据我的理解,C++ QT并发阻塞MappedReduced v.s MappedReduced,c++,qt,qtconcurrent,C++,Qt,Qtconcurrent,根据我的理解,QtConcurrent::blockingMappedReduced返回最终结果,而QtConcurrent::MappedReduced返回一个QFuture对象,但在本例中,我看到了如下代码: WordCount total = QtConcurrent::mappedReduced(files, countWords, reduce); QtConcurrent::mappedReduced函数还返回最终结果。我错过什么了吗?如果这是错误的,那么使用QtConcurren
QtConcurrent::blockingMappedReduced
返回最终结果,而QtConcurrent::MappedReduced
返回一个QFuture
对象,但在本例中,我看到了如下代码:
WordCount total = QtConcurrent::mappedReduced(files, countWords, reduce);
QtConcurrent::mappedReduced
函数还返回最终结果。我错过什么了吗?如果这是错误的,那么使用QtConcurrent::mappedReduced
返回的结果的正确方法是什么?在什么条件下我应该QtConcurrent::mappedReduced
而不是QtConcurrent::blockingMappedReduced
?请告知。在示例中,QFuture
对象使用QFuture对象直接返回到WordCount
,该对象阻塞并等待结果变为可用
typedef QMap<QString, int> WordCount;
WordCount total = mappedReduced(files, countWords, reduce);
如果要与QFuture对象交互(暂停、恢复、检查结果是否就绪),则可以通过调用mappedReduced
而不使用阻塞函数来异步处理它
QFuture future=mappedReduced(文件、countWords、reduce);
qDebug()我猜示例代码使用的方法与调用WordCount total=QtConcurrent::mappedReduced(files,countWords,reduce).result()相同你能再解释一下什么转换运算符吗?我阅读了文档,没有发现任何解释@Talamaki您可以定义一个类的成员函数,称为转换函数,用于将其类的类型转换为另一个指定类型。有关更多详细信息,请参阅。请稍微解释一下future.isResultReadyAt(0)的含义@塔拉玛基
WordCount total = blockingMappedReduced(files, countWords, reduce);
QFuture<WordCount> future = mappedReduced(files, countWords, reduce);
WordCount total = future.result();
QFuture<WordCount> future = mappedReduced(files, countWords, reduce);
qDebug() << future.isResultReadyAt(0); // returns false