lin*_*llo 5 qt connect signals-slots qslider
我想将QSlider连接到QDoubleSpinBox,但是当代码编译得很好并且运行简单的QSpinBox时,它对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)) );
Run Code Online (Sandbox Code Playgroud)
小智 6
QSlider和QDoubleSpinBox在valueChanged
/中setValue
使用不同类型的参数(QSlider使用int,QDoubleSpinBox当然使用双精度).更改滑块信号和插槽的参数类型可能会有所帮助:
connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(int)) );
connect(horizontalSlider1,SIGNAL(valueChanged(int)),spinBox1,SLOT(setValue(double)) );
Run Code Online (Sandbox Code Playgroud)
我不确定Qt是否可以为您自动处理此类型转换; 如果没有,您将必须定义自己的插槽以在正确的对象上调用setValue()