一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

第一种,使用lambda表达式

1  QFuture<void> future = QtConcurrent::run([=]() {
2      // Code in this block will run in another thread
3  });
4  ...

第二种,使用成员函数

调用QByteArray的成员函数split()

1  // call 'QList<QByteArray>  QByteArray::split(char sep) const' in a separate thread
2  QByteArray bytearray = "hello world";
3  QFuture<QList<QByteArray> > future = QtConcurrent::run(bytearray, &QByteArray::split, ',');
4  ...
5  QList<QByteArray> result = future.result();

调用非成员函数:

1  // call 'void QImage::invertPixels(InvertMode mode)' in a separate thread
2  QImage image = ...;
3  QFuture<void> future = QtConcurrent::run(&image, &QImage::invertPixels, QImage::InvertRgba);
4  ...
5  future.waitForFinished();
6  // At this point, the pixels in 'image' have been inverted

 

posted on 2024-01-29 15:35  一杯清酒邀明月  阅读(269)  评论(0编辑  收藏  举报