Reputation: 2719
This is a method that I call from a button click
void ChangeLabelText(QLabel* myLabel)
{
int countNumber = 0;
for(int i = 0; i < 9999; i++)//outer loop
{
for(int k = 0; k < 65000; k++)//inner loop
{
countNumber++;
}
myLabel->setText(QString::number(countNumber));
}
}
When the code runs text of the label is set at the end of the outer loop
, but I expected it to set label's text every time inner loop
finishes. What might be causing it?
Upvotes: 0
Views: 371
Reputation: 819
Your code executed in the main thread and in the main thread th UI update happens on events callbacks. What you need is to force repaint your ui. You can do it by calling repaint()
or by asking aplication to process events with QCoreApplication::processEvents()
. You need to make it after changing label.
Upvotes: 1