Update QLabel text in a loop
Solved
General and Desktop
-
wrote on 2 Jun 2018, 17:27 last edited by A Former User 6 Feb 2018, 17:27
Hi,
I am trying to show the result of each step of my algorithm in a QLabel to verify the execution, but the QLabel doesn't change.
I think the problem is because each step take 5 second approximately but I don't understand the problem.Here is the part of my code :
for(int t(0) ; t < limit ; t++) { /* execution of the step t of the algorithm ( 5 second approximately ) */ resultLabel->setText("result"+ <result here>) }
I also tried to do it with a QMessageBox::information and it works, but I have to click Ok every time :
for(int t(0) ; t < limit ; t++) { /* execution of the step t of the algorithm ( 5 second approximately ) */ QMessageBox::information(this,"result",<result here>) }
Thanks
-
wrote on 2 Jun 2018, 17:45 last edited by
Hi, you can force a refresh of your QLabel by calling processEvents():
for(int t(0) ; t < limit ; t++) { /* execution of the step t of the algorithm ( 5 second approximately ) */ resultLabel->setText("result"+ <result here>); qApp->processEvents(); `}
-
wrote on 2 Jun 2018, 18:54 last edited by A Former User 6 Feb 2018, 19:04
Thanks for your answer, unfortunately this part of my code is executed in a class that inherits from QMainWindow, I don't have access to the QApplication.
Edit:
It works using QCoreApplication::processEvents() instead.
1/3