views:

113

answers:

1

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

connect(pObject1, signal1, pObject2, slot2)

For instance, one can write something like:

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

With Boost::Signal the syntax we would write it this way:

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

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

+4  A: 

The thing with Qt is that it goes through a code generation phase during compilation, that Boost can't do. That means that Qt can do some very clever syntactic things that can't be copied without going through a similar process.

To quote Wikipedia:

Known as the moc, this is a tool that is run on the sources of a Qt program. It interprets certain macros from the C++ code as annotations, and uses them to generate additional C++ code with "Meta Information" about the classes used in the program. This meta information is used by Qt to provide programming features not available natively in C++: the signal/slot system, introspection and asynchronous function calls.

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

Edit: I think the Wikipedia quote is quite clear that the signal/slot system is implemented using the moc. I doubt very much that there's any way to use the same syntax without using a similar system.

Skilldrick