Catching the value of a spinbox
Solved
General and Desktop
-
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:
//.h private slots: ... void captureValue(int v); ... //.cpp //Constructor <NombreClase>(){ ... 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 :)