Demonstrates how to pass each object in the container to a member function of different class instance using boost::bind. You can alternatively do this by overloading operator() [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 Test(const Object& object) const { return 1.0f;} // Note, this function MUST be const!
  14. };
  15.  
  16. int main()
  17. {
  18.   QVector<Object> v;
  19.   Object a;
  20.   v.push_back(a);
  21.  
  22.   MyClass myClass;
  23.  
  24.   QVector<float> result = QtConcurrent::blockingMapped<QVector<float> >(v.begin(), v.end(), boost::bind(&MyClass::Test, &myClass, _1));
  25.  
  26.   std::cout << result[0] << std::endl;
  27.   return 0;
  28. }