1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Qt5:error: no matching function for call to 'MainWindow::connect()

Qt5:error: no matching function for call to 'MainWindow::connect()

时间:2024-01-15 19:29:35

相关推荐

Qt5:error: no matching function for call to 'MainWindow::connect()

报错代码:

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版本的语法

信号槽语法

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。