Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is slot keyword still required?
Forum Updated to NodeBB v4.3 + New Features

Is slot keyword still required?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sidewinder
    wrote on last edited by
    #1

    Hello,
    Qt 5 introduces a new "QObject::connect":http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#connect-4 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.

    Regards,

    "Never memorize what you can look up in books."
    Albert Einstein

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sidewinder
        wrote on last edited by
        #3

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

        "Never memorize what you can look up in books."
        Albert Einstein

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          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!
          greetz

          Greetz, Jeroen

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved