简体   繁体   中英

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

改成

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM