Problem with connecting QLabel to QSlider

590 views Asked by At

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));
}

1

There are 1 answers

0
paxdiablo On BEST ANSWER
QObject::connect(this, SIGNAL( slider.valueChanged(int)), this , SLOT( zmiana(int)) );

I don't think that's correct, you're connecting the signal of the Loads object to the slot but the Loads object is not the one generating the signal, the slider object is doing that.

Hence I think you'll need slider as the first argument, not this. Using this as the third argument is okay, I believe, since the slot does belong to the Loads object.