Yevhen
Yevhen

Reputation: 1965

qt preprocessor

What is the order of compiling in QT? as I understood it is impossible to write

 
#define BEGIN_SIGNALS signals:

is the only way to make conditional compilation only using


#ifdef QT
signals:
#endif

Upvotes: 4

Views: 1893

Answers (3)

Martin Beckett
Martin Beckett

Reputation: 96109

You can do it the other way around.

If not QT then define 'signals' as 'protected' - which is what Qt does anyway so that compiler doesn't trip up. You also need to define Q_OBJECT, emit() and connect() to do nothing.

ps. You do sometimes need to do this, I have a low level lib that carefully doesn't depend on Qt - but it can send a Qt signal when an event occurs. Without Qt it can send a windows event or a callback function.

Upvotes: 0

Rohan Prabhu
Rohan Prabhu

Reputation: 7302

  1. What is the point of using a macro for an anyway custom keyword?
  2. The meta-object compiler invokes the C++ preprocessor, so you're pretty much good using macros for those keywords.
  3. If not Qt, then what other toolkit do you expect to rely on for an event-mechanism? In my opinion, there is no point in using overlapping toolkits for development unless you wish to keep specific functionality which can be configured (at compile time in a build setting) which relies on Qt. In this case, you are better off using semantics from a toolchain (automake, cmake, whatever you use).

Upvotes: 0

shoosh
shoosh

Reputation: 78934

Just tested it and

#define BEGIN_SIGNALS signals:

does actually work as expected since moc does the preprocessing as well.
The order of compilation for a QObject class MyQObject is -

start moc for MyQObject.h
   moc run the C preprocessor
   moc produces the moc_MyObject.cpp file
moc_MyObject.cpp is compiled by the native compiler

MyQObject.cpp is compiled by the native compiler before or after this.

Be mindful that the word signals itself is a macro that translates to protected when the native compiler is used. so I'm not sure why you would ever want to define something like this BEGIN_SIGNALS

Upvotes: 2

Related Questions