6
votes

Suppose I have a QPushButton widget that is connected to a slot by its clicked() signal. This first slot in turn calls another slot by the emit keyword. The second slot takes an argument from the first slot and do something with it. It worked, but from what I understand of the signals-slots pattern, it only makes sense to emit a signal. Is it wrong to emit a slot instead of a signal?

3

3 Answers

9
votes

If you look at the definition of emit, you can see that it is empty. emit is just used to indicate that a signal is emitted at that line. Therefore, emitting a slot does not make sense.

Slots are regular functions, you can call them explicitly.

6
votes

Yes. A slot is a function. You can simply call a slot like any other function in C++ doSlotAction(params);. Only signals should follow the emit keyword.

3
votes

Just to complete the previous answers, signals are really protected methods implemented by moc, the meta-object compiler.