Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - emitting slots instead of signals

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?

like image 260
liewl Avatar asked Feb 08 '10 11:02

liewl


3 Answers

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.

like image 85
erelender Avatar answered Sep 28 '22 07:09

erelender


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.

like image 20
Corey D Avatar answered Sep 28 '22 07:09

Corey D


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

like image 30
e8johan Avatar answered Sep 28 '22 05:09

e8johan