After 18 months ... I started with comments in response to @Mat and quickly left the room. So the answer.
IMO emit is neither syntactic sugar nor a simple keyword in the sense that
- It generates code (as described in @Mat above),
- This helps the
connect mechanism recognize that it really is a signal and - It makes your signal part a βlargerβ system, where signals and responses (slots) can be executed synchronously or asynchronously or in a queue depending on where and how the signal was emitted. This is an extremely useful feature of the signal / slot system.
The entire signal / slot system is a different idiom than a simple function call. I believe this is due to the observer pattern. There is also a big difference between signal and a slot : a signal does not need to be implemented, whereas a slot must be!
You walk along the street and see the house on fire (signal). You dial 911 (connect the fire signal with the 911 response slot). The signal was emitted, and the slot was implemented by the fire department. It may be inaccurate, but you get this idea. Consider the OP example.
Some server objects know how much has been done. Thus, it can simply signal emit progressNotification(...) . It depends on the class that the actual progress bar displays in order to receive this signal and execute it. But how does the connection connect to this signal? Welcome to the Qt Signal / Slot System. Now you can imagine a manager class (usually a kind widget), which consists of a view object and a data calculation object (both are QObjects ), can perform connect (m_myDataEngine, &DataEngine::progressNotification, m_myViewObj, &SimpleView::displayProgress) .
Not to go into the constructive aspects of the manager class, but suffice it to say that this is where the signal / slot system shines. I can focus on developing a very clean architecture for my application. Not always, but often times, I believe that I just emit signals, but I realize slots.
If you can use / call the signal method without emitting it, then this necessarily means that you never needed this function as a signal in the first place.
NameRakes Jan 07 '17 at 22:52 2017-01-07 22:52
source share