views:

144

answers:

3

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  A: 

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.

Corey D
This conveys the wrong meaning. emitting actually conveys the meaning of sending a signal and a connected slot being called back, where as the _keyword_ emit does itself nothing, it's just for better readability.
penguinpower
+3  A: 

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.

erelender
+1  A: 

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

e8johan