How to achieve QT-like syntax for signal connections using Boost :: Signal

In QT, we can connect signals and slots using the following simple syntax:

connect(pObject1, signal1, pObject2, slot2) 

For example, you could write something like:

 A a; B b; connect(&a, SIGNAL(valueChanged(int)), &a, SLOT(setValue(int))); 

With Boost :: Signal syntax, we will write this:

 A a; B b; a.valueChanged.connect(boost::bind(&B::SetValue, &b, _1)) 

IMHO, forcing signal syntax is more complex. Is there a way to make Boost :: Signal's syntax more like QT.

+4
source share
1 answer

The thing with Qt is that it goes through the stage of generating code at compile time, which Boost cannot do. This means that Qt can do very smart syntax things that cannot be copied without going through a similar process.

To quote Wikipedia :

Known as moc, it is a tool that runs on the sources of the Qt program. He interprets certain macros from C ++ code as annotations and uses them to generate additional C ++ code with the help of "Metadata" about classes used in the program. This meta-information is used by Qt to provide programming functions that were not initially available in C ++: signal / slot systems, introspection, and asynchronous function calls.

(I can't get the link to work, but it is http://en.wikipedia.org/wiki/Qt_(framework) )

Edit: I think the Wikipedia quote is clear that the signal / slot system is implemented using moc. I highly doubt that you can use the same syntax without using a similar system.

+4
source

Source: https://habr.com/ru/post/1301554/


All Articles