Important: Please read the Qt Code of Conduct -

Catching the value of a spinbox

  • if (ui->spinBox->value()==20){
            ui->label_2->setText("low stock");

    Im trying to change the text of a label when the value of spinbox is 20.
    However this code does not do anything.
    i tried storing the value in a variable and that also does not work .
    Please help.
    Thank you.

  • You must capture valueChanged(int) signal from the spinner:

    private slots:
        void captureValue(int v);
        connect(ui->spinbox, SIGNAL(valueChanged(int)), this, SLOT(captureValue(int)));
    void <NombreClase>::captureValue(int v)
        if(v < 20) ui->label_2->setText("low stock");
        else if(v >= 20 && v <= 300) ui->label_2->setText("normal stock");
        else ui->label_2->setText("high stock");

  • @Camilo-del-Real
    That worked.
    Thanks :)