Using QSlider to change the value of a variable

不羁岁月 提交于 2019-12-02 16:38:03

问题


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 
    ...
}

My question is how can I connect the SIGNAL of the slider to the setValue(double) SLOT.

Thanks in advance.


回答1:


slider is already a pointer, e.g. remove the '&'

connect( slider, SIGNAL((slider->valueChanged())), this, SLOT(setValue(double)) );

Edit: 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().



来源:https://stackoverflow.com/questions/14120165/using-qslider-to-change-the-value-of-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!