liewl
liewl

Reputation: 4071

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?

Upvotes: 5

Views: 4546

Answers (3)

e8johan
e8johan

Reputation: 2939

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

Upvotes: 3

zweihander
zweihander

Reputation: 6315

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.

Upvotes: 10

Corey D
Corey D

Reputation: 4689

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.

Upvotes: 7

Related Questions