I want to connect a QSlider to a QDoubleSpinBox but while the code compiles fine and runs for simple QSpinBox, it doesn't work for QDoubleSpinBox
QSlider *horizontalSlider1 = new QSlider();
QDoubleSpinBox *spinBox1 = new QDoubleSpinBox();
connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(double)) );
connect(horizontalSlider1,SIGNAL(valueChanged(double)),spinBox1,SLOT(setValue(double)) );
QSlider and QDoubleSpinBox take different types of arguments in valueChanged
/setValue
(QSlider uses ints and QDoubleSpinBox uses doubles, of course). Changing the argument type for the slider's signal and slot might help:
connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(int)) );
connect(horizontalSlider1,SIGNAL(valueChanged(int)),spinBox1,SLOT(setValue(double)) );
I'm not sure if Qt can automatically handle this type conversion for you; if not, you'll have to define your own slots to call setValue() on the correct object
You'll have to add your own slot which converts the argument type and emits a signal or updates the slider directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With