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

QProgressBar



  • I am new to QT...

    I am trying to create an application which reads some data from the database... while retreving the data i want to show the progress bar.

    Since i don't know how much amount of time will application take for retreving the data, so i m using the following code for creating busy progress bar.

    @static int count;
    progressbar = new QProgressBar(this);
    @

    on the START button click event i m setting

    @progressBar->setMinimum(0);
    progressBar->setMaximum(0);
    progressBar->setValue(++count);@

    If user wants to stop the process in between i have given a CANCEL button
    on the CANCEL button click event i m setting

    @progressBar->reset();@

    But if I click on CANCEL button, the progress bar keeps on running, it doesn't reset.

    Please let me know if i m missing something here.

    [Edit: Code highlighting / Vass]



  • Try on cancel this:
    @progressBar->setMaximum(100);
    progressBar->setValue(0);@
    For example.

    And wrap your code in @ tags please (right button on panel)



  • I used the following code:

    @void MainWindow::on_Start_Button_clicked()
    {
    progressBar->setMaximum(100);
    progressBar->setValue(0);
    }

    void MainWindow::on_Stop_Button_clicked()
    {
    progressBar->reset();
    }@

    It show the progess as 0% constantly.
    Please let me know what is wrong with the code.



  • Hi,

    if you set minimum and maximum, you tell progress bar its limits.
    You aditionally have to set progressBar->setValue(amountDone); with amountDone = % done. then you will see progress.



  • Hi....
    I don't know how much time will my application take for retreving the data, so in that case i m using the busy progressbar by setting maximum/minimum to 0/0.

    @void MainWindow::on_Start_Button_clicked()
    {
    static int count = 0;
    progressBar->setMaximum(0);
    progressBar->setMinimum(0);
    progressBar->setValue(count++);
    }
    void MainWindow::on_Stop_Button_clicked()
    {
    progressBar->reset();
    }@

    This shows me the busy progress bar, but if i click on Stop button the progress bar is not getting reset. Please let me know do i need to do anything else for resetting the progress bar.



  • if min = max = 0, the progress bar is busy. To stop that, set min = 0, max = 1.



  • Thanks... it works :)



  • Or, you simply hide the progress bar, since nothing is progressing anyway.


Log in to reply