Suddenly noted the presence in Qt help of such a record, declaring the signal constant:

class SomeClass : public QObject { Q_OBJECT signals: void someSignal() const; ... }; 

In the case of slots and methods, the presence of const understandable. But in the case of the signal ... Should it be interpreted as the fact that the slot receiver should not change the object that sent the signal?

    2 answers 2

    Constant signals can be sent from constant methods.

    • Hmm, you're right. Out of the blue he stumbled, missing the obvious. Thank. - alexis031182

    The signal in Qt is no different from the usual function (method) therefore all those modifiers are applicable to it, which is applicable to ordinary functions (methods). How to interpret this? In my opinion it is not necessary, because const signals, in my opinion, a phenomenon out of the ordinary. Yes, you can do it, but absolutely pointless. I have never met this in practice, and I saw a lot of different code on Qt.

    The only meaning of such a record I see is the sending of a signal from a constant object, but this is contrary to logic, since an immutable object should not signal anything.

    PS Signal can not impose any restrictions on the slot. It is not his concern what will be done on that end.

    • Maybe this is somehow connected with the new syntax of connections, which was introduced in the fifth version of the framework? Methods can be contacted directly and a compliance check is performed at compile time. So of course for connections through strings (macros SIGNAL () and SLOT ()) it turns out nonsense. - alexis031182
    • I looked in Google and found several applications of such signals - people use them to emit a signal from const methods. In my opinion there is something wrong with the design, but, nevertheless, people use it. - ixSci
    • I encountered this for the first time; it had never occurred to me to call signals from constant methods, but it seems that it can be useful if the object itself is not modified in the method body, but some calculations are made, the result of which can be passed to the side. - alexis031182
    • I do not know, in my opinion it is wrong, all the same signal reports about some event. In the constant method, no event can occur that the outside world can see, a priori. Those. sending a signal from a constant method is some kind of problem in architecture, most likely. - ixSci