Qt QtConcurrent::run()函数的两种写法


第一种,使用lambda表达式

1 QFuture<void> future = QtConcurrent::run([=]() ); 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



上一篇:Qt QCustomPlot 使用教程

下一篇:CODESYS 仿真运行


Qt
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图