I have a problem. I've created a class, in which I have a slider and a label. I want to connect these with the QObject::connect, but when I do it, nothing happens. Can you tell me what am I doing wrong?
My class:
class Loads :public QObject
{
Q_OBJECT
public:
QSlider slider;
QLabel label;
QMainWindow okno;
Loads();
private:
int wart;
public slots:
void zmiana(int li);
};
Class "Loads" constructor:
Loads::Loads()
{
okno.setGeometry(300,300,300,300);
label.setParent(&okno);
slider.setParent(&okno);
label.setGeometry(0,0,300,200);
slider.setGeometry(0,200,300,100);
slider.setMinimum(1);
slider.setMaximum(30);
label.setText("0");
wart=0;
QObject::connect(this, SIGNAL( slider.valueChanged(int)), this , SLOT( zmiana(int)) );
okno.show();
}
My "zmiana" slot
void Loads::zmiana(int li)
{
wart=li;
label.setText(QString::number(li));
}
I don't think that's correct, you're connecting the signal of the
Loads
object to the slot but theLoads
object is not the one generating the signal, theslider
object is doing that.Hence I think you'll need
slider
as the first argument, notthis
. Usingthis
as the third argument is okay, I believe, since the slot does belong to theLoads
object.