@kshegunov said in Function after setupUi():
Probably flooding the main thread's event loop.
Okey I optimized a code little bit:
QtConcurrent::run([=]() {
int i;
int value;
double dResult = 1;
for(i = 0;i < 20000000;i++) {
dResult = qExp(qCos(qTan(qSin(qPow(qSqrt(((((i * 1337) / 7) * 73) * 1329) % 1937),7) * dResult)) / qAsin(qPow(qSin(dResult * i * qTan(1337 * i)), 29))));
if((i % 200000) == 0) {
value = i / 200000;
emit showResult(QString::number(dResult));
emit pBarSetValue(value);
}
}
emit showResult(QString::number(dResult));
emit pBarSetValue(100);
});
It tooks few seconds for my CPU, but yea UI is responsible and progressbar is changing in realtime
Problem was because
emit showResult(QString::number(dResult));
emit pBarSetValue(i);
runs 5000000 times
I don't follow. Add a stop signal where? You run a function imperatively with the proposed QtConcurent::run (as C++ is an imperative language), you can't just break in the middle of it ...
I dont know, maybe that Quit Application signal will tell to OS scheduler that scheduler has to kill worker thread
So only disadvantage of that method is that I cannot stop worker thread in middle of operation?
//EDIT, thanks for help :)