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