Cutom events use case



  • Hello,
    I've been reading about Qt event system and found out that one can create their own custom events.
    It appears that custom events work very similarly to signal-slot mechanism. So what would be the use case for custom events? Why not just use signals and slots? Is there any advantage in using custom events instead of signals and slots?

    Thanks for your answers.


  • Moderators

    @Eligijus said in Cutom events use case:

    It appears that custom events work very similarly to signal-slot mechanism.

    They have some mechanics in common, but still their field of usage is different.
    Signals have a 1:n relationship, where events have a 1:1 relationship. Events also have the advantage that you can use an even-filter, which isn't possible with signals-slots.
    You can install an event filter on the QApplication instance and filter an event before it is sent to any object.

    Some events support event-compression, means multiple events in the same event-loop iteration get compressed to a single event (like the paint event for example). Unfortunately this isn't possible for custom events yet though. (Without a dependency to private Qt classes)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.