如题,当在connect当中使用Lambda表达式时,要注意前面使用的信号是否有多个重载,这时需要处理信号重载问题:1.可用static_case; 2.使用QOverload::of
错误的示例:
connect(comboBoxDicomPrinter, SIGNAL(QComboBox::currentTextChanged(const QString&)),
[=](const QString& str){ QString sss = str; });
编译会提示:C2664 “QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const”: 无法将参数 3 从“PrintFilmRightPanel::createLayout0::<lambda_9bfa24493f8bb475295dc334521f524e>”转换为“const char *”
正确的示例1(static_case):
connect(comboBoxDicomPrinter,
static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
[=](const QString& str){ QString sss = str; });
正确的示例2(QOverload::of):
connect(comboBoxDicomPrinter,
QOverload<const QString&>::of(&QComboBox::currentTextChanged),
[=](const QString& str) { QString sss = str; });