2

I have a large array of float. I would like to call QtConcurrent::map() on it and change the values in place.

Can I do that without making a copy of the array? It seems map() takes a QVector as parameter and I can't find a mean to initialize a QVector from an array without making a copy.

demonplus
  • 5,613
  • 12
  • 49
  • 68
Octo
  • 543
  • 1
  • 5
  • 16

1 Answers1

1

QtConcurrent also has versions with STL-style iterators. Raw pointers have the properties of STL-style iterators for this purpose.

float x[] = {1.3f, 2.5f, 4.6f};
QFuture<void> f = QtConcurrent::map(x, x+3, [](float & a) { a = 2*a; });
f.waitForFinished();
qDebug() << x[0] << x[1] << x[2];

This prints:

2.6 5 9.2
majk
  • 827
  • 5
  • 12