Boost logo

Boost :

Subject: Re: [boost] Preliminary submission of Boost Synapse
From: Vladimir Prus (vladimir.prus_at_[hidden])
Date: 2015-06-16 17:11:36


On 6/16/2015 10:56 AM, Emil Dotchevski wrote:
> On Tue, Jun 16, 2015 at 12:04 AM, Vladimir Prus <vladimir.prus_at_[hidden]>
> wrote:
>
>> On 6/16/2015 3:52 AM, Emil Dotchevski wrote:
>>
>>> I've made changes to Boost Synapse (a signal programming library) in part
>>> based on feedback I received on the Boost mailing list, and I've uploaded
>>> the updated source code and documentation to github:
>>> http://zajo.github.io/boost-synapse/.
>>>
>>
>> Emil,
>>
>> I've glanced through the tutorial and examples. The way you make signals
>> 'external' to
>> the class is quite smart.
>>
>> However, I have two questions:
>>
>> - There does not appear a way, given QObject*, to determine which signals
>> are attached to it. Such reflection is one of the primary reasons MOC
>> still exists, so your library will not eliminate the need for MOC?
>>
>
> I'm not an expert on Qt and there might be more reasons to need MOCing, but
> I know for a fact that it is needed in order to add new signals to an
> existing type.

Yes, that's correct. The benefit of using moc compared to say, boost.signals,
is that you can connect to a signal by name. Say, all of QML depends on
ability to bind to signals from C++ objects from a JavaScript (or similar) code,
where static typechecking is not available.

> If you want to have a QDialog that emits your own custom
> signals you must derive from QDialog, add the signals and MOC. Using
> Synapse this can be avoided.

Correct. Although if I have a QDialog I already have pretty strong dependency
on Qt.

>> - Looking at the first example, I can't help wondering why I would want
>> to use the library - given that I can use QObject::connect, either
>> classic
>> or with function object, why would I use an extra library?
>>
>
> It really depends - if you're willing to couple any amount of your own code
> with Qt, then you (obviously?) don't need Synapse. To me it is useful for
> similar reasons that boost::function is useful: it lets me pull things
> apart and decouple them. In the few Qt programs I've written, I'm using
> Synapse as glue between the user interface code and the rest of the
> program, while the UI code itself (being already coupled with Qt) mostly
> doesn't use Synapse internally (except to add custom signals since I don't
> use MOC.)
>
> Anyway, Synapse wasn't motivated by Qt, but by having to hook up callbacks
> from other APIs that weren't quite as good as Qt, only it turned out it's
> more practical than that. For example, one problem that has been quite
> annoying for me in the past is how to connect a boost::function to a
> Windows message. Synapse makes this a no-brainer.

Oh, that's indeed a cool thing to have. So Synapse is generally a way to
externally attach modern-style signals to class that otherwise might not
have a good signal mechanism. Seems like a useful functionality to me.

> I guess this is really what defines the library: it lets you connect a
> boost::function to, dare I say, anything? :)

Thanks for explaining :-)

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk