Qt文档阅读笔记-QtConcurrent Map Example官方实例解析
生活随笔
收集整理的這篇文章主要介紹了
Qt文档阅读笔记-QtConcurrent Map Example官方实例解析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這個例子對數據處理有很大的用處,在此記錄下。
官方對應這個例子解析如下:
QtConcurrent Map exapmle展示了使用QtConcurrent API的同步(阻塞)接口對圖片進行拉伸。這個程序是控制臺程序。
一共有兩個文件:
main.cpp
#include <QImage> #include <QList> #include <QThread> #include <QDebug> #include <QGuiApplication> #include <qtconcurrentmap.h>QImage scale(const QImage &image) {qDebug() << "Scaling image in thread" << QThread::currentThread();return image.scaled(QSize(100, 100), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); }int main(int argc, char *argv[]) {QGuiApplication app(argc, argv);const int imageCount = 20;// Create a list containing imageCount images.QList<QImage> images;for (int i = 0; i < imageCount; ++i)images.append(QImage(1600, 1200, QImage::Format_ARGB32_Premultiplied));// Use QtConcurrentBlocking::mapped to apply the scale function to all the// images in the list.QList<QImage> thumbnails = QtConcurrent::blockingMapped(images, scale);return 0; }map.pro
TEMPLATE = app TARGET = mapdemo QT += concurrent CONFIG += console CONFIG -= app_bundleSOURCES += main.cpptarget.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/map INSTALLS += target程序運行截圖如下:
這里可以看到有很多進程去處理。
?
下面對上面的關鍵代碼進行解釋:
T QtConcurrent::blockingMapped(const Sequence &sequence, MapFunction function)對sequence中的每一個調用下MapFunction,此函數的返回值為MapFunction的返回值的集合。
注意:這個函數是會被阻塞的,但所有項都執行完function后才會向下繼續運行。
QImage::Format_ARGB32_Premultiplied:一種圖片存儲格式;
Qt::IgnoreAspectRatio:放縮自由,不保留高度。
Qt::SmoothTransformation:使用雙線性濾波,對圖片進行平滑出處理。
?
總結
以上是生活随笔為你收集整理的Qt文档阅读笔记-QtConcurrent Map Example官方实例解析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis文档阅读笔记-Pub/Sub官
- 下一篇: Qt文档阅读笔记-QtConcurren