使用QSlider更改变量的值
问题描述:
我尝试使用 QSlider
更改变量的值,
I'm trying to use QSlider
to change the value of a variable,
#include <QSlider>
class MainThread : public QWidget{
Q_OBJECT
public:
MainThread(QWidget *parent=0);
private slots:
void setValue(double);
private:
QSlider *slider;
};
MainThread::MainThread(QWidget *parent):QWidget(parent){
slider = new QSlider(Qt::Horizontal,0);
connect(&slider, SIGNAL((slider->valueChanged())),
this, SLOT(setValue(double))); // here's my problem
...
}
可以将滑块的 SIGNAL
连接到 setValue(double)
SLOT。
My question is how can I connect the SIGNAL
of the slider to the setValue(double)
SLOT.
提前感谢。
答
slider已经是一个指针,例如移除&'
slider is already a pointer, e.g. remove the '&'
connect( slider, SIGNAL((slider->valueChanged())), this, SLOT(setValue(double)) );
编辑:这将不工作,因为信号没有参数。
将setValue(double)重命名为setValue(),并使用slider-> value()从滑块中获取值。
This won't work, since the signal has no argument. Rename the setValue(double) to setValue() and get the value from the slider with slider->value().