QtConcurrent blockingMap whith QPainterPath
-
Hello everyone,
In my application I have to subtract a lot of QPainterPath to one base QPainterpath. This works well but is very slow. I think QtConcurrent could help me speed up it all but this my first experience with threads and I'm not sure on how to do this.
I first tried this:
void RectangleItem::substPath(QPainterPath &path){ m_shape = m_shape.subtracted(path); }
And in a member function of RectangleItem:
QVector<QPainterPath> paths = collidingPaths(bRect); QFutureSynchronizer<void> synchronizer; for (int i = 0; i < paths.count(); i++ ) synchronizer.addFuture(QtConcurrent::run(this, &RectangleItem::substPath, paths.at(i))); synchronizer.waitForFinished();
But some paths were not substracted, I suspect that my path base was in an inconsitent state and decided to add a mutex in the substPath function. Wich worked but was as long as the single threaded function (As I undestand the mutex lock the base path variable during the execution of the thread so my multpile calls to QtConcurrent::run ends up in a linear function, am I Right?)
I then saw QtConcurrent::blockingMap but get stuck implementing it with my members variable / functions.
Any help would be greatly appreciated :)
Thank you
-
Hi,
You are trying to modify the same variable from several threads so in any case you have something linear. In your case, why not pass your paths list to that function and execute the loop there ? That won't freeze your GUI and you don't need any locking and also you'll keep the order of the removal.
-
-
How do you expect to execute in parallel a series of ordered operations on a single object ?