c++ – How to use a QProgressBar

c++ – How to use a QProgressBar

You dont need to create a QProgressBar in your main, it will automatically be created when you call new Ui::MainWindow().

void valueChanged() is a signal so you are not supposed to call it, but connect slots to it. I suggest you read this page if you are not familiar with Qts signal/slots system: http://doc.qt.io/qt-5/signalsandslots.html

You should start by setting up the progress bar correctly in your MainWindow constructor:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{        
    ui->battery->setOrientation(Qt::Horizontal);
    ui->battery->setRange(0, 100); // Lets say it goes from 0 to 100
    ui->battery->setValue(10); // With a current value of 10

    ui->setupUi(this);
}

Then you should be able to create your own signals and connect them to void QProgressBar::setValue(int) to change the progress bar value.
You can also call setValue() directly from where you are doing you are doing your processing if it is in scope.

Hope it helps!

c++ – How to use a QProgressBar

Leave a Reply

Your email address will not be published.