Demonstrates how to pass each object in the container to a member function of different class instance. You can alternatively do this using boost::bind [developer.qt.nokia.com]

  1. #include <QtConcurrentMap>
  2. #include <QVector>
  3.  
  4. #include <boost/bind.hpp>
  5.  
  6. #include <iostream>
  7.  
  8. class Object{};
  9.  
  10. class MyClass
  11. {
  12. public:
  13.   float operator()(const Object& object) { return 1.0f;}
  14.   typedef float result_type;
  15. };
  16.  
  17. int main()
  18. {
  19.   QVector<Object> v;
  20.   Object a;
  21.   v.push_back(a);
  22.  
  23.   MyClass myClass;
  24.  
  25.   QVector<float> result = QtConcurrent::blockingMapped<QVector<float> >(v.begin(), v.end(), myClass);
  26.  
  27.   std::cout << result[0] << std::endl;
  28.   return 0;
  29. }