使用QSlider更改变量的值 [英] Using QSlider to change the value of a variable

查看:1816
本文介绍了使用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().

这篇关于使用QSlider更改变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆