Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtConcurrent blockingMap whith QPainterPath
Qt 6.11 is out! See what's new in the release blog

QtConcurrent blockingMap whith QPainterPath

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yonnak
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yonnak
        wrote on last edited by
        #3

        Hi,

        Thanks for your reply. Processing all the substratcion in a single function and put it in a thread works well and is not freezing the GUI, but the processing time is still quite long. Is there no way execute a parrallel substraction on a path?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How do you expect to execute in parallel a series of ordered operations on a single object ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved