Qt 信号与槽使用错误 :error: no matching function for call to……

匿名 (未验证) 提交于 2019-12-02 22:56:40
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_39978855/article/details/83082095

代码:

 QObject::connect(comboBoxVersion, &QComboBox::currentIndexChanged, this, &RepositoryWidget::slotDisplayVersion);

执行上面语句,提示如下错误,connect 采用的是 Qt 5 的语法,问题原因是函数 currentIndexChanged 函数重载,有两个不同形参:
void currentIndexChanged(int index)和 void currentIndexChanged(const QString &)
编译器不知道要使用哪个函数。

error: no matching function for call to 'RepositoryWidget::connect(QComboBox*&, <unresolved overloaded function type>, RepositoryWidget*, void (RepositoryWidget::*)(const QString&))'。

方法:

1. 强制类型转换

 QObject::connect(comboBoxVersion, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), this, &RepositoryWidget::slotDisplayVersion);

2.使用QT5之前的语法

 QObject::connect(comboBoxVersion, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(slotDisplayVersion(const QString &)));

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!