Results 1 to 16 of 16

Thread: Selective signaling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Selective signaling

    Quote Originally Posted by csaken View Post
    Basically we are talking about same thing, except the fact that you are using a list of Item's to hold the N observers, and at each event you are traversing the entire list of observers, to notify the observers if they are interested (you can have 10000 of observers, while only the last one is interested in the event you want to notify him about) , while I'm using N lists of observers, one for each type of event, and I use the list of slots registered on helper object's signal.
    See my comment in the code - I know it's inefficient, I only wanted to show the functionality without cluttering the code too much.

    If your code were storing for each event type a list of notifiers, and then the solution was mostly the same, except of course the fact that in your code you have the loop to deliver the event, while I'm using Qt's signal-slot calling, which basically in the end reduces down to same thing, going over a list of interested parties, and call them.
    What happens (with your code) when one object subscribes to multiple types of messages or messages of the same type coming from different objects? How does handleEvent() look like then?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Sep 2009
    Location
    Targu Mures, Romania
    Posts
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Selective signaling

    Usually each processor handles one type of event or a small group of events.
    If I decide to subscribe the same processor to more than one event, nothing changes in the way they are registered, or how it's called.

    From the event router's point of view does not matter, since he has for each event type a QObject,and each of these helper objects has a list if slots queued up.

    Still, in this case, in the Processor's code, I have to check for what signal was called, and proceed accordingly. However, the processors get called only for the event types they are interested in.

    Qt Code:
    1. Processor1::handleEvent(Event* e)
    2. {
    3. if(typeofEvent is Event1) { ... }
    4. if(typeofEvent is Event2) { ... }
    5. }
    6.  
    7. EventRouter r;
    8. Processor p;
    9. r.register(typeofEvent1, &p);
    10. r.register(typeofEvent2, &p);
    11.  
    12. r.fireEvent(new Event1()) // triggers Processor 1, since is in the typeofEvent1's list of queued slots for event() signal
    13. r.fireEvent(new Event2()) // also triggers Processor 1, since it is also in the list of typeofEvent1;s list of queued slots for event() signal.
    To copy to clipboard, switch view to plain text mode 

    Also, the event sending mechanism I want to be lousy coupled, I'm not interested in who sent the event, I'm only interested in getting it from somewhere, and handling it then possibly send some more events, somewhere. Controllers on different layers will take care of sending up/down the events, although they are also not interested from where comes, only the direction, up or down (I think, I'm still ironing out things on this side)
    Last edited by csaken; 30th April 2010 at 09:28.

Similar Threads

  1. Replies: 0
    Last Post: 19th February 2010, 17:28
  2. QT emit/signaling thread-safe?
    By richy in forum Qt Programming
    Replies: 1
    Last Post: 14th July 2006, 09:37
  3. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.