开发者

qt preprocessor

What is the order of compiling 开发者_如何学Goin 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


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


  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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜