void ThreadWatcher2::run() {
/* QSignalMapper* signalMapper = new QSignalMapper();
for (int i=0; i<6; i++) {
connect(thread[i], SIGNAL(finished()), signalMapper, SLOT(map()));
signalMapper->setMapping(thread[i], i); }
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
*/
connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
connect(thread[0], SIGNAL(finished()), this, SLOT(finishedHandler0()));
connect(thread[1], SIGNAL(finished()), this, SLOT(finishedHandler1()));
connect(thread[2], SIGNAL(finished()), this, SLOT(finishedHandler2()));
connect(thread[3], SIGNAL(finished()), this, SLOT(finishedHandler3()));
connect(thread[4], SIGNAL(finished()), this, SLOT(finishedHandler4()));
connect(thread[5], SIGNAL(finished()), this, SLOT(finishedHandler5()));
}
void ThreadWatcher2::timeoutHandler() {
for (int i=0; i<6; i++)
window[i]->update();
if (threadsLeft==0)
}
void ThreadWatcher2::finishedHandler(int i) {
updateLabels(i);
}
void ThreadWatcher2::finishedHandler0() {
updateLabels(0);
}
void ThreadWatcher2::finishedHandler1() {
updateLabels(1);
}
void ThreadWatcher2::finishedHandler2() {
updateLabels(2);
}
void ThreadWatcher2::finishedHandler3() {
updateLabels(3);
}
void ThreadWatcher2::finishedHandler4() {
updateLabels(4);
}
void ThreadWatcher2::finishedHandler5() {
updateLabels(5);
}
inline void ThreadWatcher2::updateLabels(int t) {
alive[t] = false;
threadsLeft--;
seconds[t] = (float)runTime[t] / 1000.0f;
if (seconds[t] == 0.0f)
seconds[t] = 0.001f;
time[t
]->setText
("Time: "+QString::number(seconds
[t
],
'g',
3));
if (isFirst) {
isFirst = false;
long minTime = runTime[t];
min = t;
long x;
for (int k=0; k<6; k++) {
x = runTime[k];
if ((x > -1) && (x < minTime)) {
minTime = x;
min = k; } }
if (min != t) {
seconds[min] = (float)runTime[min] / 1000.0f;
if (seconds[min] == 0.0f)
seconds[min] = 0.001f; }
if (min == t)
ratio[t]->setText("Ratio: 1x");
else {
ratio
[t
]->setText
("Ratio: "+QString::number(seconds
[t
]/seconds
[min
],
'g',
3)+"x");
} } else
ratio
[t
]->setText
("Ratio: "+QString::number(seconds
[t
]/seconds
[min
],
'g',
3)+"x");
}
void ThreadWatcher2::run() {
/* QSignalMapper* signalMapper = new QSignalMapper();
for (int i=0; i<6; i++) {
connect(thread[i], SIGNAL(finished()), signalMapper, SLOT(map()));
signalMapper->setMapping(thread[i], i); }
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(finishedHandler(int)));
*/
connect(updateTimer, SIGNAL(timeout()), this, SLOT(timeoutHandler()));
connect(thread[0], SIGNAL(finished()), this, SLOT(finishedHandler0()));
connect(thread[1], SIGNAL(finished()), this, SLOT(finishedHandler1()));
connect(thread[2], SIGNAL(finished()), this, SLOT(finishedHandler2()));
connect(thread[3], SIGNAL(finished()), this, SLOT(finishedHandler3()));
connect(thread[4], SIGNAL(finished()), this, SLOT(finishedHandler4()));
connect(thread[5], SIGNAL(finished()), this, SLOT(finishedHandler5()));
QThread::exec();
}
void ThreadWatcher2::timeoutHandler() {
for (int i=0; i<6; i++)
window[i]->update();
if (threadsLeft==0)
QThread::exit(0);
}
void ThreadWatcher2::finishedHandler(int i) {
updateLabels(i);
}
void ThreadWatcher2::finishedHandler0() {
updateLabels(0);
}
void ThreadWatcher2::finishedHandler1() {
updateLabels(1);
}
void ThreadWatcher2::finishedHandler2() {
updateLabels(2);
}
void ThreadWatcher2::finishedHandler3() {
updateLabels(3);
}
void ThreadWatcher2::finishedHandler4() {
updateLabels(4);
}
void ThreadWatcher2::finishedHandler5() {
updateLabels(5);
}
inline void ThreadWatcher2::updateLabels(int t) {
alive[t] = false;
threadsLeft--;
seconds[t] = (float)runTime[t] / 1000.0f;
if (seconds[t] == 0.0f)
seconds[t] = 0.001f;
time[t]->setText("Time: "+QString::number(seconds[t],'g',3));
if (isFirst) {
isFirst = false;
long minTime = runTime[t];
min = t;
long x;
for (int k=0; k<6; k++) {
x = runTime[k];
if ((x > -1) && (x < minTime)) {
minTime = x;
min = k; } }
if (min != t) {
seconds[min] = (float)runTime[min] / 1000.0f;
if (seconds[min] == 0.0f)
seconds[min] = 0.001f; }
if (min == t)
ratio[t]->setText("Ratio: 1x");
else {
ratio[t]->setText("Ratio: "+QString::number(seconds[t]/seconds[min],'g',3)+"x"); } }
else
ratio[t]->setText("Ratio: "+QString::number(seconds[t]/seconds[min],'g',3)+"x");
}
To copy to clipboard, switch view to plain text mode
thanks
Bookmarks