Results 1 to 14 of 14

Thread: QTimer / QThread question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Apr 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer / QThread question

    Well, here's another problem. When all delay is removed the sorting is instantaneous. In this case 1-2 of the signals dissapear. The commented out portion uses the QSignalMapper, which has the same problem. I tried the Qt::QueuedConnection option but no help. Any ideas? I'd guess you can't max out the event loop so easily.

    Qt Code:
    1. void ThreadWatcher2::run() {
    2. /* QSignalMapper* signalMapper = new QSignalMapper();
    3.   for (int i=0; i<6; i++) {
    4.   connect(thread[i], SIGNAL(finished()), signalMapper, SLOT(map()));
    5.   signalMapper->setMapping(thread[i], i); }
    6.   connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
    7. */
    8. connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
    9. connect(thread[0], SIGNAL(finished()), this, SLOT(finishedHandler0()));
    10. connect(thread[1], SIGNAL(finished()), this, SLOT(finishedHandler1()));
    11. connect(thread[2], SIGNAL(finished()), this, SLOT(finishedHandler2()));
    12. connect(thread[3], SIGNAL(finished()), this, SLOT(finishedHandler3()));
    13. connect(thread[4], SIGNAL(finished()), this, SLOT(finishedHandler4()));
    14. connect(thread[5], SIGNAL(finished()), this, SLOT(finishedHandler5()));
    15.  
    16. QThread::exec();
    17. }
    18. void ThreadWatcher2::timeoutHandler() {
    19. for (int i=0; i<6; i++)
    20. window[i]->update();
    21.  
    22. if (threadsLeft==0)
    23. QThread::exit(0);
    24. }
    25. void ThreadWatcher2::finishedHandler(int i) {
    26. updateLabels(i);
    27. }
    28. void ThreadWatcher2::finishedHandler0() {
    29. updateLabels(0);
    30. }
    31. void ThreadWatcher2::finishedHandler1() {
    32. updateLabels(1);
    33. }
    34. void ThreadWatcher2::finishedHandler2() {
    35. updateLabels(2);
    36. }
    37. void ThreadWatcher2::finishedHandler3() {
    38. updateLabels(3);
    39. }
    40. void ThreadWatcher2::finishedHandler4() {
    41. updateLabels(4);
    42. }
    43. void ThreadWatcher2::finishedHandler5() {
    44. updateLabels(5);
    45. }
    46. inline void ThreadWatcher2::updateLabels(int t) {
    47. alive[t] = false;
    48. threadsLeft--;
    49. seconds[t] = (float)runTime[t] / 1000.0f;
    50. if (seconds[t] == 0.0f)
    51. seconds[t] = 0.001f;
    52. time[t]->setText("Time: "+QString::number(seconds[t],'g',3));
    53.  
    54. if (isFirst) {
    55. isFirst = false;
    56. long minTime = runTime[t];
    57. min = t;
    58. long x;
    59.  
    60. for (int k=0; k<6; k++) {
    61. x = runTime[k];
    62. if ((x > -1) && (x < minTime)) {
    63. minTime = x;
    64. min = k; } }
    65.  
    66. if (min != t) {
    67. seconds[min] = (float)runTime[min] / 1000.0f;
    68. if (seconds[min] == 0.0f)
    69. seconds[min] = 0.001f; }
    70.  
    71. if (min == t)
    72. ratio[t]->setText("Ratio: 1x");
    73. else {
    74. ratio[t]->setText("Ratio: "+QString::number(seconds[t]/seconds[min],'g',3)+"x"); } }
    75. else
    76. ratio[t]->setText("Ratio: "+QString::number(seconds[t]/seconds[min],'g',3)+"x");
    77. }
    To copy to clipboard, switch view to plain text mode 
    thanks
    Last edited by Galen; 15th April 2010 at 07:49.

Similar Threads

  1. QThread and QTimer
    By sivrisinek in forum Qt Programming
    Replies: 4
    Last Post: 30th April 2009, 16:41
  2. QThread & QTimer
    By hosseinyounesi in forum Qt Programming
    Replies: 5
    Last Post: 13th April 2009, 08:22
  3. QTimer and QThread in Qtopia 4.2.0
    By mellibra in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 25th October 2007, 08:26
  4. QTimer and QThread
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2006, 14:52
  5. Qthread n QTimer Problem
    By quickNitin in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2006, 14:12

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
  •  
Qt is a trademark of The Qt Company.