Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

new QProgressDialog - QProgressBar displayed on first time only.



  • Hi,
    when user calls the sendAll routine below, I construct a new QProgressDialog from scratch, set the necessary stuff, open it and keep it updated. It shows the progress as intended. Afterwards it is closed and deleted.

    But: calling sendAllSlot a second (third...) time, though the dialog opens, the progress bar itself is never to be seen. I have also tried this with a QProgressBar, same problem. It works only on first run.

    I guess that I am doing something fundamentally and idiotically wrong. But what?

    void MainWindow::sendAllSlot()
    {
        bool sent = true;
        if (QMessageBox::question(nullptr, "Alle versenden","Sind Sie sicher?")
                == QMessageBox::Yes) {
            int i = 0;
            QProgressDialog *p = new QProgressDialog();
            p->reset();
            p->setMinimum(0);
            p->setValue(0);
            p->setMaximum(m_recipientsFiltered.count());
            p->setMinimumDuration(1);
            p->show();
            for (; i < m_recipientsFiltered.count(); i++) {
                p->setValue(i);
                Recipient* r = m_recipientsFiltered.at(i);
    
                sent = sendOneMail(r);
                if (!sent) {
                    // User has not provided sufficient information. We leave the for-loop before doing anything.
                    QMessageBox::about(nullptr, "Abbruch", "Der Vorgang wurde abgebrochen");
                    break;
                }
            }
            p->reset();
            p->close();
            delete p;
        }
    }
    


  • Ok, solved.

    p->setModal(true);
    

    finally did the trick for me. I'll leave this for people with the same problem.


  • Lifetime Qt Champion

    Hi,

    Since you only use that dialog within that method, you can use the stack rather than the heap. It will automatically delete the dialog at the end of the if statement.


Log in to reply