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.5k 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.
  • SGaistS SGaist

    How did you determine the version from Qt Creator ?

    In any case, you should first try to build your application with your distribution provided Qt.

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

    @SGaist
    I looked at the help about dialogue in Qt Creator to get "5.5".

    Yeah. I'm using the version installed with the Mint software manager (5.5), so it's the same version as I'd get with "apt-get install". I don't know how to access Qt via Anaconda as it is not on the Anaconda menu.

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

    1 Reply Last reply
    0
    • mranger90M Offline
      mranger90M Offline
      mranger90
      wrote on last edited by
      #9

      I'm still convinced this is a coding issue, not configuration.
      try this to see if the progress dialog is shown correctly: (m_timer is a QTimer)

      void Dialog::on_showProgress1_clicked()
      {
          QProgressDialog *dlg = new QProgressDialog(this);
          connect(dlg, &QProgressDialog::finished, dlg, &QProgressDialog::deleteLater);
          connect(dlg, &QProgressDialog::canceled, this, [=](){
              m_progressVal = 99;  // kind of cheesy, let the timer continue and cleanup
          });
      
          dlg->setRange(0,100);
          dlg->setWindowTitle("Test");
          dlg->setLabelText("Updating...");
          m_progressVal = 0;
      
          auto conn = std::make_shared<QMetaObject::Connection>();
          *conn = connect(&m_timer, &QTimer::timeout, this, [=]() {
              m_progressVal++;
              dlg->setValue(m_progressVal);
      
              if (m_progressVal == dlg->maximum()) {
                  m_timer.stop();
                  disconnect(*conn);
              }
          });
      
          dlg->show();
      
          m_timer.setInterval(100);
          m_timer.start();
      }
      
      
      GuerrianG 1 Reply Last reply
      2
      • mranger90M mranger90

        I'm still convinced this is a coding issue, not configuration.
        try this to see if the progress dialog is shown correctly: (m_timer is a QTimer)

        void Dialog::on_showProgress1_clicked()
        {
            QProgressDialog *dlg = new QProgressDialog(this);
            connect(dlg, &QProgressDialog::finished, dlg, &QProgressDialog::deleteLater);
            connect(dlg, &QProgressDialog::canceled, this, [=](){
                m_progressVal = 99;  // kind of cheesy, let the timer continue and cleanup
            });
        
            dlg->setRange(0,100);
            dlg->setWindowTitle("Test");
            dlg->setLabelText("Updating...");
            m_progressVal = 0;
        
            auto conn = std::make_shared<QMetaObject::Connection>();
            *conn = connect(&m_timer, &QTimer::timeout, this, [=]() {
                m_progressVal++;
                dlg->setValue(m_progressVal);
        
                if (m_progressVal == dlg->maximum()) {
                    m_timer.stop();
                    disconnect(*conn);
                }
            });
        
            dlg->show();
        
            m_timer.setInterval(100);
            m_timer.start();
        }
        
        
        GuerrianG Offline
        GuerrianG Offline
        Guerrian
        wrote on last edited by Guerrian
        #10

        @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!
            }
        }
        

        Linux Mint 18.3
        Qt 5.14.1
        Qt Creator 4.11.1

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