The Linux Page

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

Today I noticed that I was getting this warning while running one of my tests1:

   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 the documentation 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 get that 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 event name 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.)

  • 1. I had not noticed before... Unfortunately, you get a s**t load of output under the Windows IDE about the loading of DLLs which no one really cares about and that often blurs your view of other much more important messages!

Re: QtWarning QMetaObject::connectSlotsByName: No matching ...

Thank you! You gave the solution to my problem.

Kind of strange naming convention become slot connecting mechanism, in my view. But now that I know how it works, it's advantages might become apparent.

Once again, thank you! :-)

Re: QtWarning QMetaObject::connectSlotsByName: No matching ...

Solution works, many thanks!