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?
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.
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.
Just to complete the previous answers, signals are really protected methods implemented by moc, the meta-object compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With