Search code examples
c++qtqt5signals-slots

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

Solution

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