QMetaObject::connectSlotsByName: No matching signal

独自空忆成欢 提交于 2019-11-26 22:25:16

问题


I set a QT menu, which is automatically connected with action function on_actionOpen_triggered(). Later I want to pass a filename string to this function in order to call this function manually in a special condition. So I changed the function signature to on_actionOpen_triggered( const char *filename_in ). After this change the program is running well, but there is a complain in terminal,

QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered(const char*)

I am wondering what happened, and how I can add arguments for this menu action functions.

Thank you.


回答1:


Qt autoconnection mechanism can't find suitable signal to your slot. For menu item there's no signal that would match your slot with one argument, and signal must not have fewer arguments than slot.

You can change slot's name so that it won't try to find a matching signal, and use QObject::connect directly instead of QMetaObject::connectSlotsByName. Moreover you'll have to assign default value to your argument filename_in if you want connect to work with triggeredsignal.




回答2:


I was facing same Warning/Error QMetaObject::connectSlotsByName: No matching signal for

And got simple solution. For Example:

Problem :
QMetaObject::connectSlotsByName: No matching signal for on_actionOpen_triggered(const char*) Warning You just need to change the name of the Slot

Solution
Change Slot name like on_actionOpenTriggered and this warning disappear.

Hint
Qt try to understand its default slot like on_<name_of_object>_<action>, So if you specify any slot with above signature, Qt will throw warning.

Hope it will help to someone.



来源:https://stackoverflow.com/questions/24355023/qmetaobjectconnectslotsbyname-no-matching-signal

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