Catching the value of a spinbox
Solved
General and Desktop
-
wrote on 7 Sept 2016, 15:12 last edited by ronyNS 9 Jul 2016, 15:44
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. -
wrote on 7 Sept 2016, 17:52 last edited by
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"); }
-
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"); }
wrote on 8 Sept 2016, 06:40 last edited by@Camilo-del-Real
That worked.
Thanks :)
3/3