No matching signal for on_something_event

QtWarning QMetaObject::connectSlotsByName: No matching signal for on_something_event()

Search with Google I found a post that explained, very clearly, what happens. I'd bet it's somewhere in thedocumentation of Qt, but so far I have not found anything about that in the event sections I read.

The fact is that the setupUi() function, which is created when you generate a window using Designer or Qt Creator, does a special search on all the functions named on_widgetName_eventName() functions and attempts to connect them. This is neat, although it means that if you have a slot named that way which is not directly related to a widgetName and a valid eventName for that widget, the connect() call fails and you getthat warning at runtime.

You have two solutions here:

1) Rename your functions to not use on_... as the introducer (i.e. you could use slot_... instead, or the Qt naming convention such as onName1Name2()...)

2) Rename your functions so the auto-connect happens as expected!

In the second case, you need to rename the function to match the widget name exactly and then the eventname exactly. For example, if you have a QPushButton named clickHere, you could create a function named:

   on_clickHere_clicked()

and that function will be called any time the user clicks your clickHere button (and of course you don't have to do the connect yourselves.)

阅读(11) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值