Results 1 to 3 of 3

Thread: QThread trying to limit threads

  1. #1
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QThread trying to limit threads

    I have a function in my code that takes a list of points () from a QMap with key 'linekey'. Linekey is a QString describing which 'Line' I want to get from the map. My code is as follows:

    Qt Code:
    1. foreach (const QString linekey, linekeys) {
    2.  
    3. if (groupValues.contains(linekey))
    4. continue;
    5. QList<ReceiverGraphicsItem *> receiverlist = lineGroup.values(linekey);
    6. if (lod <= .03) {
    7. points2[0] = mapToPix(receiverlist.at(0)->pos());
    8. points2[1] = mapToPix(receiverlist.at(receiverlist.size()/4)->pos());
    9. points2[2] = mapToPix(receiverlist.at((receiverlist.size()*2)/4)->pos());
    10. points2[3] = mapToPix(receiverlist.at((receiverlist.size()*3)/4)->pos());
    11. points2[4] = mapToPix(receiverlist.at((receiverlist.size()-1))->pos());
    12. ptrr.drawPolyline(points2,small);
    13. } else {
    14. points[0] = mapToPix(receiverlist.at(0)->pos());
    15. points[1] = mapToPix(receiverlist.at(receiverlist.size()/14)->pos());
    16. points[2] = mapToPix(receiverlist.at((receiverlist.size()*2)/14)->pos());
    17. points[3] = mapToPix(receiverlist.at((receiverlist.size()*3)/14)->pos());
    18. points[4] = mapToPix(receiverlist.at((receiverlist.size()*4)/14)->pos());
    19. points[5] = mapToPix(receiverlist.at((receiverlist.size()*5)/14)->pos());
    20. points[6] = mapToPix(receiverlist.at((receiverlist.size()*6)/14)->pos());
    21. points[7] = mapToPix(receiverlist.at((receiverlist.size()*7)/14)->pos());
    22. points[8] = mapToPix(receiverlist.at((receiverlist.size()*8)/14)->pos());
    23. points[9] = mapToPix(receiverlist.at((receiverlist.size()*9)/14)->pos());
    24. points[10] = mapToPix(receiverlist.at((receiverlist.size()*10)/14)->pos());
    25. points[11] = mapToPix(receiverlist.at((receiverlist.size()*11)/14)->pos());
    26. points[12] = mapToPix(receiverlist.at((receiverlist.size()*12)/14)->pos());
    27. points[13] = mapToPix(receiverlist.at((receiverlist.size()*13)/14)->pos());
    28. points[14] = mapToPix(receiverlist.at((receiverlist.size()-1))->pos());
    29. ptrr.drawPolyline(points,big);
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 
    The ptrr is a QPainter that is connected to a QPixmap (QImage in threaded version!).

    This works fine but is slow with hundreds of lines to draw; thus the idea is to use Threads. if I use the loop method directly as it was but in a thread class then I get hundreds of threads; My question is, how do I make it so that only x number of threads run at one time? I have heard of a queue but have not seen one example of it. Maybe there is a better way to split up this job to use threading?


    thank you,

    JW
    sw developer

    "Some days you just can't get rid of a bomb." Batman movie - 1966

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread trying to limit threads

    Read about QtConcurrent.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread trying to limit threads

    Thanks, but after reading about QtConcurrent and other articles you have posted on threading. I decided another approach would be better serving. I now have 2 threads for the two items of concern and they do all of the work in the background after I put up a temp pixmap.


    JW
    sw developer

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  3. Struggling with QThread...
    By TemporalBeing in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2009, 20:46
  4. Replies: 0
    Last Post: 26th September 2008, 21:33
  5. Using QUdpSocket within a QThread
    By db in forum Newbie
    Replies: 18
    Last Post: 30th October 2007, 23:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.