目录
  1. 1. Qcombox对象
Qt5信号重载

Qcombox对象

见代码

1
2
3
connect(ui->comboBox, &QComboBox, this, [=](int index){
ParameterSettingDialog_currentIndexChanged(i, index);
});

对于QComboxBox对象,这样的信号槽链接,直接使用会报编译错误

1
no matching member function for call to 'connect'

出现这样错误的愿意大致是QComboBox的信号有重载实现导致

1
2
3
4
5
6
7
8
9
Q_SIGNALS:
void editTextChanged(const QString &);
void activated(int index);
void activated(const QString &);
void highlighted(int index);
void highlighted(const QString &);
void currentIndexChanged(int index);
void currentIndexChanged(const QString &);
void currentTextChanged(const QString &);

解决方法:

1
2
3
4
5
6
7
8
9
10
11
// 两种正确方式:
// 方式1:
typedef void (QComboBox::*QComboIntSignal)(int);
connect(ui->comboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged), this, [=](int index){
ParameterSettingDialog_currentIndexChanged(i, index);
}););

// 方式2:
connect(ui->comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index){
ParameterSettingDialog_currentIndexChanged(i, index);
});
文章作者: XyLan
文章链接: https://blog.xylan.cn/2023/04/26/Qt5%E4%BF%A1%E5%8F%B7%E9%87%8D%E8%BD%BD/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 XyLan
打赏
  • 微信
  • 支付寶