QT 同名信号无法识别的问题

QCompleter 类有如下信号

Q_SIGNALS:
void activated(const QString &text);
void activated(const QModelIndex &index);  

按照以往的写法,会如下去连接信号

connect(mCompleterPtr, &QCompleter::activated, this, [this](const QString& text) {
		// 槽函数实现

		});  

编译代码会报如下错误:

1>error C2664: “QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const”: 无法将参数 2 从“overloaded-function”转换为“const char *”
1> message : 上下文不允许消除重载函数的歧义
1> message : 参见“QObject::connect”的声明

采用如下连接方式可以解决上述问题

connect(mCompleterPtr, static_cast<void(QCompleter::*)(const QString&)>(&QCompleter::activated), this, [this](const QString& text) {
		// 槽函数实现

		});

  

  

猜你喜欢

转载自www.cnblogs.com/CityLcf/p/12274773.html