Results 1 to 15 of 15

Thread: Replace the typical observer pattern to the Qt's signal and slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Replace the typical observer pattern to the Qt's signal and slot

    Ok, here are some points to start with.

    - The lib you referred uses C++'s polymorphism to make calls to concrete observer class objects from a abstract observer class. You can make use of QtC++'s signals to make these calls.
    - You can replace the virtual functions (be wise, to replace only the virtual functions which are used to realize observer pattern) in the abstract observer class with signals (these signals will still be new observer manager class).
    - All the contrete observer classes which were derived from abstract observer class may no longer need do be so, i.e. they all can be indipendent classes (it's up to your design to have them in class hirarchy, to realize your functunality)
    - In the abstract observer class's abstract implementation replace calls to virtual functions with emitting correspoding signals, as said earlier.
    - In the new classes (which used to be contrete observer classes), implement corresponding slots, and and connect them to the observer manager class's signals (as and when requied to observe)
    - Replace the abstract observer, with a contrete observer manager which manages the observer connections, observable contexts, topics, subjects etc
    - Also, as expected all the new classes should be aware of the observable class, which is genreally used to register (connect a slot) an observation instance with concrete observer manager.
    - When observing to no longer is needed then disconnet the slot (un-registering the observable)

    Note that some of the terms used above may be generic in manner, just to give you a heading.

  2. #2
    Join Date
    Jan 2011
    Posts
    212
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    24

    Default Re: Replace the typical observer pattern to the Qt's signal and slot

    Hello Santosh,

    Thanks for the explanation. Now i have the following snippet that needs to be changed to Qt's signal and slot:

    Qt Code:
    1. workspace_->getProcessorNetwork()->addObserver(this);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect(processorNetwork, SIGNAL(networkChanged()),this, SLOT());
    To copy to clipboard, switch view to plain text mode 

    In the immediate above code snippet i have changed the virtual functions in the abstract observer class to corresponding and now i am confused to get the SLOT for them. Is there any hint to find the SLOT() for each of the signals. Or i have declare and define them by myself?


    Regards
    Sajjad

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Replace the typical observer pattern to the Qt's signal and slot

    Quote Originally Posted by Santosh Reddy
    - In the new classes (which used to be contrete observer classes), implement corresponding slots, and and connect them to the observer manager class's signals (as and when requied to observe)
    This should answer it...

Similar Threads

  1. Replies: 2
    Last Post: 3rd May 2011, 20:22
  2. Non-typical and Non-linear wizard
    By kornicameister in forum Qt Programming
    Replies: 4
    Last Post: 30th December 2010, 15:26
  3. File Observer in qt
    By succorguy in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 14:21
  4. Observer Design Pattern
    By joseph in forum General Programming
    Replies: 1
    Last Post: 21st January 2008, 12:17
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Tags for this Thread

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.