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



  • 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



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



  • 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.



  • 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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.