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.6k 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 Offline
    GuerrianG Offline
    Guerrian
    wrote on last edited by Guerrian
    #4

    I'm using Qt 5 on Linux Mint 18.1 (Cinnamon).

    I tried adding more "QApplication::processEvents()", but it didn't make any difference.

    I think I will have to create a separate thread for the progress dialogue.

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Qt 5 is a bit vague since it goes from 5.0.0 to 5.11.0.

      Did you install it yourself ?
      If not, do you have the same problem with the Qt version provided by Mint ?
      What window manager are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      GuerrianG 1 Reply Last reply
      0
      • SGaistS SGaist

        Qt 5 is a bit vague since it goes from 5.0.0 to 5.11.0.

        Did you install it yourself ?
        If not, do you have the same problem with the Qt version provided by Mint ?
        What window manager are you using ?

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

        @SGaist
        $ qmake -v
        QMake version 3.0
        Using Qt version 5.6.2 in /home/daniel/anaconda3/lib
        $ wmctrl -m
        Name: Mutter (Muffin)

        But Qt Creator says version 5.5.

        Linux Mint 18.3
        Qt 5.14.1
        Qt Creator 4.11.1

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #7

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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