1 year ago

#236980

test-img

Syed Iftekharuddin

QProgressbar does not respond to large values

I want to build an application that calculates large computations using an idle timer. The progress bar works fine for small numbers but if I enter large numbers as input the progress bar does not display anything. Code, where I set the QProgressbar, is as shown below.

void MainWindow::on_startButton_clicked()
{
    numberEntered = ui->inputValue->text().toInt();
    QIntValidator * validator = new QIntValidator(this);
    ui->inputValue->setValidator(validator);
    ui->progressBar->setMaximum(numberEntered);
    globalIndex = 0;
    timer->start(0);
    ui->resultArea->append(QString("STARTED"));
}

and in another place

void MainWindow::countManager()
{
    if(globalIndex == 0){
        ui->resultArea->append(QString("%1 : is a Prime number").arg(globalIndex));
        ui->progressBar->setValue(globalIndex);
    }

    if(globalIndex <= numberEntered && globalIndex != 0){
        int result = primeNumberCalculator(globalIndex);
        ui->progressBar->setValue(globalIndex);
        if(result !=0){
            ui->resultArea->append(QString("%1 : is a Prime number").arg(result));
        }
    }
    if(numberEntered == globalIndex){
        timer->stop();
        ui->resultArea->append(QString("End of count!!"));
    }
    globalIndex++;
}

qt

qtimer

qprogressbar

0 Answers

Your Answer

Accepted video resources