Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Update QLabel text in a loop
QtWS25 Last Chance

Update QLabel text in a loop

Scheduled Pinned Locked Moved Solved General and Desktop
qlabelloopsettext
3 Posts 2 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 2 Jun 2018, 17:27 last edited by A Former User 6 Feb 2018, 17:27
    #1

    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

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 2 Jun 2018, 17:45 last edited by
      #2

      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();
      `}
      
      1 Reply Last reply
      2
      • ? Offline
        ? Offline
        A Former User
        wrote on 2 Jun 2018, 18:54 last edited by A Former User 6 Feb 2018, 19:04
        #3

        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 Reply Last reply
        0

        2/3

        2 Jun 2018, 17:45

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved