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. Prefixing slot method/signal name with "Slot/Signal"?
Forum Updated to NodeBB v4.3 + New Features

Prefixing slot method/signal name with "Slot/Signal"?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.4k 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.
  • C Offline
    C Offline
    cfg83
    wrote on last edited by
    #1

    Hello -

    Do you ever see developers naming their slot methods and signals explicitly like so? :

    @class Foo : public QObject
    {
    Q_OBJECT
    public:
    Foo();
    virtual ~Foo();

    void AMethod();
    

    private:
    int m_a;

    public slots:
    void SlotDataChanged();

    signals:
    void SignalForwardDataChange();

    };
    @

    I was just thinking that this would make it easy to identify "slot methods" when you are looking at the method source code. It would also make the Qt Creator "auto complete" group the signals and slots together.

    Thanks,

    cfg83

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Sure some developers do that... you just did. If you think that helps then name them that way.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        I think this is completely redundant in the case of slots, after all a slot is still a regular function. In Qt5 you can even connect signals to functions that are not slots.

        If the label "public slots:" is not enough for you to signify slots, you can use the more portable, per declaration macro Q_SLOT before each method that you want to be registered as a slot by the meta system.

        I don't have the practice of prefixing signals either, but it might be somewhat useful in big projects.

        Keep in mind when using the old Qt4 syntax for connecting signals and slots, Creator will filter signals and slots for you.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cfg83
          wrote on last edited by
          #4

          ChrisW67 and utcenter -

          Thanks for your replies. You're right, a slot is just a regular method. My idea was that anyone that was looking at the source file could see "SlotDoSomething()" and understand the original intended purpose of the method. I don't think "SignalDoSomething()" is as necessary because there is no method body. You have to write "emit DoSomething()" which is implicitly saying (to me) "signal DoSomething()".

          cfg83

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Well, you don't have to write the emit actually. It is a macro that evaluates to nothing.

            However, I think it is a matter of carefully naming methods. Usually, I name my signals such that they signify that something has happened, while a slot will be named after the thing that will happen if you trigger it.

            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