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. QProgressDialog looks messed up / corrupted when it's first shown
Qt 6.11 is out! See what's new in the release blog

QProgressDialog looks messed up / corrupted when it's first shown

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 6.4k Views 2 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.
  • GuerrianG Guerrian

    @mranger90

    I got your example to run... nice! How would I adapt it so that I can update the progress bar from within an algorithm (assuming that is possible):

    void myAlgorithm(int n)
    {
        int i;
        for (i = 0; i < n; i++)
        {
            someProcessingFunction(i);
            // update the progress bar here!
        }
    }
    
    joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by
    #11

    @Guerrian Hi,friend.

    Very good! Don't forget to Mark as Solved in Topic Tools.

    Just do it!

    1 Reply Last reply
    0
    • GuerrianG Offline
      GuerrianG Offline
      Guerrian
      wrote on last edited by
      #12

      If you don't pause before the first (not zero) point and process events then the progress dialogue is drawn correctly. Seems like a bug with QProgressDialog.

      Linux Mint 18.3
      Qt 5.14.1
      Qt Creator 4.11.1

      mrjjM 1 Reply Last reply
      0
      • GuerrianG Guerrian

        If you don't pause before the first (not zero) point and process events then the progress dialogue is drawn correctly. Seems like a bug with QProgressDialog.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #13

        @Guerrian
        Hi
        QProgressDialog is older than god so its very unlikely you found a bug in 2018 :)
        also when you use stuff like
        QApplication::processEvents();
        QThread::sleep(1);
        it means you try to loop in a GUI application and it always do odd stuff as you are stangulating the event loop. QApplication::processEvents() can sometimes help
        but its not a cure all loops magic call.

        signals and slot often a way better choice as it plays nice with the event loop.

        GuerrianG 1 Reply Last reply
        0
        • mrjjM mrjj

          @Guerrian
          Hi
          QProgressDialog is older than god so its very unlikely you found a bug in 2018 :)
          also when you use stuff like
          QApplication::processEvents();
          QThread::sleep(1);
          it means you try to loop in a GUI application and it always do odd stuff as you are stangulating the event loop. QApplication::processEvents() can sometimes help
          but its not a cure all loops magic call.

          signals and slot often a way better choice as it plays nice with the event loop.

          GuerrianG Offline
          GuerrianG Offline
          Guerrian
          wrote on last edited by Guerrian
          #14

          @mrjj
          Can I do this with two threads, one for the GUI and the other for the algorithm?

          Linux Mint 18.3
          Qt 5.14.1
          Qt Creator 4.11.1

          mrjjM 1 Reply Last reply
          0
          • GuerrianG Guerrian

            @mrjj
            Can I do this with two threads, one for the GUI and the other for the algorithm?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #15

            @Guerrian
            Hi, yes if algorithm is heavy then its be best solution.
            You already have the GUI thread.
            So if you move the algorithm class to a thread and
            emit a signal to tell the progressbar to update then it should work lovely.
            https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
            so myAlgorithm would be the task object and moved to thread.

            GuerrianG 1 Reply Last reply
            0
            • mrjjM mrjj

              @Guerrian
              Hi, yes if algorithm is heavy then its be best solution.
              You already have the GUI thread.
              So if you move the algorithm class to a thread and
              emit a signal to tell the progressbar to update then it should work lovely.
              https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
              so myAlgorithm would be the task object and moved to thread.

              GuerrianG Offline
              GuerrianG Offline
              Guerrian
              wrote on last edited by Guerrian
              #16

              I followed this path and it is almost working. Unfortunately the cancel button on the progress bar is disabled. It remains disabled even after successfully updating the progress bar. The only thread I could find on this problem is here:
              https://forum.qt.io/topic/26619/cancel-button-on-qprogressdialog-is-unresponsive-solved
              Like the author says though you don't need to connect the cancel button to a slot.

              I am setting up the dialog like this now:

              dialog = new QProgressDialog(tr("Performing task") + "...", tr("Cancel"), 0, 4, this);
              dialog->setLabelText("Updating...");
              dialog->setWindowModality(Qt::WindowModal);
              connect(task, SIGNAL(advance()), this, SLOT(advance()));
              connect(dialog, &QProgressDialog::finished, dialog, &QProgressDialog::deleteLater);
              connect(dialog, &QProgressDialog::canceled, this, [=] ()
              {
                  thread->quit();
                  thread->wait();
                  dialog->close();
              });
              

              I'm showing the dialog like this:

                  dialog->setValue(0);
                  dialog->show();
              

              I'm advancing the progress bar like this:

              void MainWindow::advance()
              {
                  dialog->setValue(dialog->value() + 1);
                  QApplication::processEvents();
              }
              

              Another strange problem which I am encountering is that the progress bar / task is sometimes started even when I click on the menu but not the menu item. I am connecting the menu item to the function using:

              connect(ui->actionTask, &QAction::triggered, this, &MainWindow::runTask);
              

              Linux Mint 18.3
              Qt 5.14.1
              Qt Creator 4.11.1

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #17

                Hi
                Does it enter the "cancel" lambda ?

                GuerrianG 1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  Does it enter the "cancel" lambda ?

                  GuerrianG Offline
                  GuerrianG Offline
                  Guerrian
                  wrote on last edited by Guerrian
                  #18

                  @mrjj
                  No, it can't, because the cancel button is disabled on the QProgressDialog.

                  Linux Mint 18.3
                  Qt 5.14.1
                  Qt Creator 4.11.1

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    But do you mean is disabled as in setEnabled(false)
                    or simply is unresponsive ?

                    GuerrianG 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      But do you mean is disabled as in setEnabled(false)
                      or simply is unresponsive ?

                      GuerrianG Offline
                      GuerrianG Offline
                      Guerrian
                      wrote on last edited by Guerrian
                      #20

                      @mrjj
                      I think the problem is that I disabled the menu using:

                      setEnabled(false);
                      

                      When I click cancel the lambda is called twice.

                      However I don't understand why the action is triggered even when I just select the menu and not the menu item. Perhaps this merits another question on this forum.

                      Is it neccessary to use a mutex and flag that the algorithm has been cancelled?

                      Linux Mint 18.3
                      Qt 5.14.1
                      Qt Creator 4.11.1

                      1 Reply Last reply
                      0

                      • Login

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