Public functions versus public slots

Viewed 3586

In my one year of Qt programming, I have learnt a lot about signals and slots. But not enough...

http://doc.qt.io/qt-5/signalsandslots.html

Slots can be used for receiving signals, but they are also normal member functions.

So... Is there any reason not to declare every single function in a class that inherits from QObject, as a slot, whether it needs to be one or not ?

In the link above, they give an example:

A small QObject-based class might read:

#include <QObject>

class Counter : public QObject
{
    Q_OBJECT

public:
    Counter() { m_value = 0; }

    int value() const { return m_value; }

public slots:
    void setValue(int value);

signals:
    void valueChanged(int newValue);

private:
    int m_value;
};

Why define the value() function as a plain function and not a slot ? Would there be any negative results if they did make it a slot ?

5 Answers
Related