报错代码:
connect(ui->chartComboBox,&QComboBox::currentIndexChanged,this,&MainWindow::getChartIndex);
报错内容:
E:\Qt_Project\QtCharts\mainwindow.cpp:22: error: no matching function for call to 'MainWindow::connect(QComboBox*&, <unresolved overloaded function type>, MainWindow*, void (MainWindow::*)(int))'
connect(ui->chartComboBox,&QComboBox::currentIndexChanged,this,&MainWindow::getChartIndex);
报错原因:
在使用QComboBox类的信号函数时,因为函数currentIndexChanged重载,出现多个参数,导致Qt5编译器不知道要匹配那个函数,于是就出现了unresolved overloaded function type这种情况。
void currentIndexChanged(int index);
void currentIndexChanged(const QString &);
解决方法:
1、强制类型转换
connect(ui->chartComboBox,static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged),this,&MainWindow::getChartIndex);
connect(ui->chartComboBox,static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),this,&MainWindow::getChartIndex);
2、改用Qt4版本的语法