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. Qt progressbar update value
Forum Updated to NodeBB v4.3 + New Features

Qt progressbar update value

Scheduled Pinned Locked Moved Solved General and Desktop
qprogressbar
3 Posts 2 Posters 6.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cdcc0606
    wrote on 17 May 2016, 10:29 last edited by
    #1

    I have a progressbar in my code.
    ui->progressBar->setRange(0, Nbr_TSendConfig);
    ui->progressBar->setValue(0);
    ui->progressBar->show();
    Here is part of my code.
    while(sendleft.length()>0)
    {
    bool flag;
    flag=true;

                taille=sendleft.indexOf(";;;;");
                send=sendleft.left(taille);
                sendleft.remove(0,taille+4);
                if(!data1.sendCardConfig(flag,send,taille))
                {
                    QMessageBox::critical(this, tr("Erreur"), tr("Echec de la configuration!"), QMessageBox::Ok);
                    ui->progressBar->hide();
                    return 0;
                }
                nbr_T++;
                ui->progressBar->setValue(nbr_T);
            }
    

    with this code, sometimes it works fine. But sometimes, il blocks the update of the progress bar, and after a few seconds it jumps to 100% directly at the end.
    Why this happens? Is my code lack of something? How can I fix it?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 17 May 2016, 10:51 last edited by
      #2

      Hi
      Your while loop might kill the global event loop and all stops to draw.
      Try calling
      qApp->processEvents();
      in the loop.
      This is just a workaround. If you need longer lasting loops you should
      try to avoid for loops and see if u can design a solution using signals and slots.
      Or use a thread.

      In any case if for LOOP in the GUI thread too much . all will stop to work. :)

      1 Reply Last reply
      1
      • C Offline
        C Offline
        cdcc0606
        wrote on 17 May 2016, 13:16 last edited by
        #3

        you are right, now it works fine.

        1 Reply Last reply
        0

        1/3

        17 May 2016, 10:29

        • Login

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