[Qt-interest] Convert to signal and slot

Sajjad dosto.walla at gmail.com
Fri Jul 22 23:58:53 CEST 2011


Hello Ross,

Thanks for the useful suggestion!

On Fri, Jul 22, 2011 at 5:06 AM, Ross Bencina <rossb-lists at audiomulch.com>wrote:

> From: "William Gordon Rutherdale (rutherw)"
> >> 21.07.2011, 21:42, "Sajjad" <dosto.walla at gmail.com>:
> >> > Hello forum,I have a project where they have the observer pattern
> >> implemented and i want to re-implement it using the Qt's signal and
> >> slot mechanism.
> >>
> >> Are you sure you need it? You can freely use observer pattern with Qt.
> >>
> >
>



> > In other words (for the benefit of the original poster), Qt already
> > provides observer semantics.  That's what signal / slot / connect() is
> > for.
>
> I would ask are the original poster, are you sure signals/slots are the
> best
> approach for what you're doing?
>

I am not sure if it is the best option to go for.


>
> Signals and slots are not always the best option for implementing "The
> Observer Pattern" (whatever that is, it has many interpretations).
>
> In my view, if you have a complex conduit of change (not just a single
> "notify()" type event) you are better off defining an abstract listener
> type
> and formalising the relationship between observer and observed, rather than
> gluing things together with a bunch of signals.
>

The API i am dealing with do have a complex conduit of change.


>
> Then instead of:
>
> connect(...
> connect(...
> connect(...
> connect(...
> connect(...
> connect(...
>
> for all of the individual events you need (and often you need a lot of
> them,
> as in Qt ModelView) you just subclass from a listener base class and say:
>
> observed->addListener( this );
>
> Of course the oposite is also true: if you have a single event, Qt's
> connect() is much easier than subclassing a listener.
>
> All approaches have their merits. Boost-style C++ template-based callback
> adapters are another option if you don't want to get moc involved. I use
> this for notifications in layers where I'm not prepared to interested in
> introducing Qt dependencies.
>

My only reason to get it done all in Qt because, they have some of the
notification using the abstract observer class and
some of them using the Qt's signal and slot mechanism. I believe that they
have foreseen the issues that you have explained right now.

My target was to get them done all using the Qt's signal and slot and now
the conversion process is making me confused me as well. I have changed all
 the virtual functions of the observer class to signal and do not know how
to define the slot and who take care of the slot, the subject or the
observer manager.

Thanks
Sajjad


>
> Ross.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110722/aa4b3cce/attachment.html 


More information about the Qt-interest-old mailing list