打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
QMetaObject::connectSlotsByName: No matching signal for问题的解决方法
userphoto

2019.04.28

关注

今天发现qt程序在运行时命令行窗口会弹出下面的警告:

QMetaObject::connectSlotsByName: No matching signal for ...

但实际功能并没有受影响。网上google了一圈,终于找到原因。

 

After a bit of sleuthing to find the source of all the Qt warnings, “QMetaObject::connectSlotsByName: No matching signal for …”, in our log window/file, here’s what I’ve found.

setupUi calls connectSlotsByName which parses the moc_ file in order to connect slots and signals. The moc_ file contains a list of all the slots for the class. The parser iterates over the list of slot names looking for the following pattern: on_objectName_signal , where on_objectName_signal is the name of the slot, objectName is the object name and signal is the signal . For example, if you have a slot named, on_doneButton_clicked(), the parser looks for an object named doneButton, a signal named clicked and then connects the on_doneButton_clicked() slot to QButton’s signal clicked().

If you follow this naming convention, you do no t need to call the connect() method, nor do you need to connect the signal via the Qt UI editor in VisualStudio. connectSlotsByName will automatically make the connection for you.

So, in order to get rid of the “No matching signal for …” warnings, we need to either follow this naming convention, or make sure none of our slot names begin with “on_”. 

上面大概就是说:用VistalStudio里的QtEditer可以自动调用Qt中“connectSlotsByName”即“按空间名称关联槽”的方式进行关联,对应的函数必须写成“on_控件名_信号名”的格式;或者也可以通过connet函数人为显式地将信号和槽关联起来。但是,如果采用显式connect的方法的同时,又将槽函数的名字起成了“on_控件名_信号名”的格式,那么就会在运行时弹出 “QMetaObject::connectSlotsByName: No matching signal for”的警告了!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
QMetaObject::connectSlotsByName: No matching signal for……
PyQt信号与槽之信号与槽的高级用法(四)
Qt MetaObject System详解之一:简介
QT Embedded二三事之QObject
Qt的slot和singnal的本质
关于eric4和pyqt的入门学习(转)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服