Jok*_*ini 5 c++ qt qt-signals qt-slot
我想做的就是在 qspinbox 和 doublespinbox 的值更改时调用一个方法。
我不需要更改旋转框的实际值,我只是希望它触发另一个方法的调用。为什么下面的代码没有错误或没有执行任何操作?连方法都不调用吗?
程序文件
connect(uiSpinBox, SIGNAL(valueChanged()), this, SLOT(slotInputChanged));
connect(uiDoubleSpinBox, SIGNAL(valueChanged()), this, SLOT(slotInputChanged));
void ColorSwatchEdit::slotInputChanged()
{
qDebug() << "Im here";
}
Run Code Online (Sandbox Code Playgroud)
标头
public:
QSpinBox *uiSpinBox;
QDoubleSpinBox *uiDoubleSpinBox;
public slots:
void slotInputChanged();
Run Code Online (Sandbox Code Playgroud)
eyl*_*esc 11
即使您不使用携带信号的数据,您也必须在连接中建立签名:
connect(uiSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotInputChanged));
connect(uiDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(slotInputChanged));
Run Code Online (Sandbox Code Playgroud)
但建议您使用新的连接语法,因为它会指示错误:
connect(uiSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &ColorSwatchEdit::slotInputChanged);
connect(uiDoubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ColorSwatchEdit::slotInputChanged);
Run Code Online (Sandbox Code Playgroud)