Change value of a QDoubleSpinBox
-
Hello everybody !
I'm currently working on an application which works with a serial port. I've designed a interface (UI) with a QDoubleSpinBox. When I get a data from the serial port, I need to change the value of a QDoubleSpinBox directly in my program with a variable. Example :
double myVar = 1.2; // 1.2 is just an example
ui->mySpinBox->setValue(myVar); // QDoubleSpinBox (UI)This code is not working. The minimum value of the spinbox is set. "setValue" need a double variable in parameter. What is the correct way to change the value of my spinbox ? If it's not possible, has someone another way to do ?
I use QtCreator 3.5.1 and Qt 5.5.1.
KevKr
-
@KevKr said in Change value of a QDoubleSpinBox:
This code is not working.
What is not working exactly?
@KevKr said in Change value of a QDoubleSpinBox:
What is the correct way to change the value of my spinbox ?
This is the correct way.
-
When my serial port is changing the value of "myVar", this value is not correctly printed in my spinbox. When I insert a qDebug(), I can see the value of myVar (1.2 in my example), but in the spinbox, the value is always -100 (the minimum value I've configured).
-
@KevKr
Yes, everything works as designed. Look up "Arguments passed by value and by reference" in this article for an explanation of why it doesn't work as you expect. -
Thank you ! Finally I've solved my problem. It was just a mistake in my algorithm, I didn't use the right variable. I've lost a couple of hours with that. Really sorry !
If someone want to get my code to change the value of a spinbox, this code is working.
Thanks !