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