Possible Duplicate:
Using QSlider to change the value of a variable
I’m trying to use the QSlider to to change a variable value:
here is a part of the code :
....
QSlider *slider = new QSlider(Qt::Horizontal,0);
connect(slider,SIGNAL(valueChanged()),this,SLOT(value(int k)));
...
the function value is a SLOT that I want to use let’s say like this:
void value (int k ) {
cout<< k << endl;
}
the problem that I have is that nothing happens when I move the slider. ?
thanks in advance
You have to put the argument
inton the signal signature to make it pass the value to the slot. Also, never put argument names in theSIGNAL(...)/SLOT(...)signature specifications.Also, make sure that
valueis a slot of your class, not a free-standing function. I guess you already put the code above in a class function, not in main or any other free-standing function, because in these there is nothisdefined. So the slot you are talking about has to be a member function, especially a QObject slot of the class you are writing this code in. Changeto
and in your class definition of
MyClassadd apublic slots:section:Also, give your slot a meaningful name, for example
sliderChanged, otherwise, chaos will rule your project sooner or later for sure.