Kaiden Prince
Kaiden Prince

Reputation: 472

Qt5 Signal and slots does not seem to work

I am trying to change a label's text to a slider's value when the slider moves. My slider is named sld_bet and my label is lbl_bet. sld_bet_changed() is a function that only has a breakpoint in it, and will eventually contain lbl_bet's modifying code.

The breakpoint is never reached, and I do not understand why.

app::app(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    connect(ui.sld_bet, SIGNAL(ui.sld_bet->sliderMoved()),
        this, SLOT(sld_bet_changed()));
}

Upvotes: 0

Views: 473

Answers (2)

CJCombrink
CJCombrink

Reputation: 3950

If you are using Qt 5, use the new connect syntax. That way the compiler will throw an error if something is not correct.

connect(ui.sld_bet, &QSlider::sliderMoved, this, &app::sld_bet_changed);

Upvotes: 3

DevGuy
DevGuy

Reputation: 636

change to

connect(ui.sld_bet, SIGNAL(sliderMoved()), this, SLOT(sld_bet_changed()));

Upvotes: 4

Related Questions