qt预处理器
QT中的编译顺序是什么?据我了解,不可能编写
#define BEGIN_SIGNALS signals:
是仅使用进行条件编译的唯一方法
#ifdef QT
signals:
#endif
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚测试了它,并且
确实按预期工作,因为 moc 也进行了预处理。
QObject
类MyQObject
的编译顺序是 -MyQObject.cpp
在此之前或之后由本机编译器编译。请注意,
signals
一词本身是一个宏,当使用本机编译器时,它会转换为protected
。所以我不确定为什么你想要定义这样的东西BEGIN_SIGNALS
Just tested it and
does actually work as expected since moc does the preprocessing as well.
The order of compilation for a
QObject
classMyQObject
is -MyQObject.cpp
is compiled by the native compiler before or after this.Be mindful that the word
signals
itself is a macro that translates toprotected
when the native compiler is used. so I'm not sure why you would ever want to define something like thisBEGIN_SIGNALS
你也可以反过来做。
如果不是 QT,那么将“信号”定义为“受保护”——这就是 Qt 所做的,这样编译器就不会出错。您还需要定义 Q_OBJECT、emit() 和 connect() 来不执行任何操作。
附:有时你确实需要这样做,我有一个低级库,小心地不依赖于 Qt - 但它可以在事件发生时发送 Qt 信号。如果没有 Qt,它可以发送 Windows 事件或回调函数。
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.