简体   繁体   English

Qt5信号和插槽似乎不起作用

[英]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 ,标签为lbl_bet sld_bet_changed() is a function that only has a breakpoint in it, and will eventually contain lbl_bet 's modifying code. sld_bet_changed()是一个只有断点的函数,最终将包含lbl_bet的修改代码。

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. 如果您使用的是Qt 5,请使用新的connect语法。 That way the compiler will throw an error if something is not correct. 这样,如果某些不正确的内容,编译器将抛出错误。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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