views:

164

answers:

3

I know how they work conceptually, but how are signals and slots implemented in the Qt framework? Qt Creator treats them as keywords, but are they simply a set of macros, or is a special pre-processor required before these source files can be compiled?

In other words, if I use Qt's signal/slot features in my code, can I easily compile it on any C++ compiler?

+7  A: 

Many features of Qt, including signals, require preprocessing the source using the Qt Meta-Object Compiler (MOC).

If you use Qt's signals feature, you can compile your source code on any compiler and platform that is supported by Qt. If you need to compile on a platform not supported by Qt, you may be out of luck or at least in for a lot of fun integration work (this is true of any library or framework, of course).

If you are looking for a cross-platform signals implementation, you might also consider Boost.Signals.

James McNellis
+1  A: 

Yes, signal and slots in Qt are implemented as macros. However MOC (Meta object compiler) is used to interpret it. MOC is a part of Qt.

If you want to use signals/slots in non Qt projects you might use Boost implementation ( http://www.boost.org/doc/libs/1_39_0/doc/html/signals.html ).

Other implementations are listed on wiki page: http://en.wikipedia.org/wiki/Signals_and_slots

Jacek
+1  A: 

You can use any compiler Qt supports. Which are the most commonly used ones, don't know if there is any widespread compiler not supported. However, the signal/slot/moc is not the limiting factor here. Signal/slots require the moc executable to be called on header files declaring QObjects and the generated code to be compiled and linked. So integrating the moc call in your existing build system might be the biggest issue. If you start from scratch, I'd suggest to go for qmake, or cmake.

Frank