Important: Please read the Qt Code of Conduct -

Is slot keyword still required?

  • Hello,
    Qt 5 introduces a new "QObject::connect": overload. It's now possible to pass a reference to a regular class (QObject based) function to be called just like explicitly declared slots used to in earlier Qt versions. Is it still required or recommended to declare member class functions as slots? I'm aware it's required if I want to use macro/string based old style connect function but I'm not sure if using slot keyword will give me any other advantages.


  • Moderators

    Without it MOC will not register that method in meta-object system. Signal-slot connection will work, but method will not be visible to QML and you will not be able to invoke it using metaObject()->invokeMethod(). If you don't use that functionality, though, you can drop the keyword, AFAIK.

  • I guess it's safe to keep declaring slots to avoid future misunderstandings or surprises.
    Thanks sierdzio.

  • In my opinion you should always declare the slots with slots to indicate that it is callable from any signal connected. It's a coding standard issue, but it will increase readability and system overview when some else if reading it. The reader can't get into your head and showing what methodes are called via Signal/Slot will help. So even if it isn't necessary always do so!

Log in to reply