QtConcurrent之blockingFilter 实现数据过滤

一、说明
void QtConcurrent::blockingFilter(Sequence &sequence, KeepFunctor filterFunction)
Calls filterFunction once for each item in sequence. If filterFunction returns true, the item is kept in sequence; otherwise, the item is removed from sequence.
Note: This function will block until all items in the sequence have been processed.
二、代码

    QList<int> sequence{1, 10, 3, 5, 6, 9, 7, 2, 4};
    QList<int> list;
    for (int i = 0; i < sequence.count(); i++) {
        if (sequence.at(i) > 5) {
            list.append(sequence.at(i));
        }
    }
    qDebug()<<"list"<<list;
    
    QtConcurrent::blockingFilter(sequence, [](int v) { return v > 5; });
    qDebug()<<"sequence"<<sequence;

你可能感兴趣的:(【Qt】)