QtConcurrent-BlockingMapped-Member-Function-of-iterated-objects

From Qt Wiki
Revision as of 11:11, 24 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search

This demonstrates how to call a member function on each item in the container and get a collection of the return values.

#include <QtConcurrentMap&gt;
#include <QVector&gt;

  1. include <iostream&gt;

class MyClass
{
public:
float Test() const // Note, this function MUST be const!
{
return 1.0f;
}
};

int main()
{
QVector&lt;MyClass&gt; v;
MyClass a;
v.push_back(a);

QVector&lt;float&gt; result = QtConcurrent::blockingMapped&lt;QVector&lt;float&gt; >(v.begin(), v.end(), &MyClass::Test);

return 0;
}