qt预处理器

发布于 2024-10-19 05:15:22 字数 165 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅暮の光 2024-10-26 05:15:22

刚刚测试了它,并且

#define BEGIN_SIGNALS signals:

确实按预期工作,因为 moc 也进行了预处理。
QObjectMyQObject 的编译顺序是 -

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 在此之前或之后由本机编译器编译。

请注意,signals 一词本身是一个宏,当使用本机编译器时,它会转换为 protected。所以我不确定为什么你想要定义这样的东西 BEGIN_SIGNALS

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

另类 2024-10-26 05:15:22
  1. 对无论如何自定义关键字使用宏有什么意义?
  2. 元对象编译器调用 C++ 预处理器,因此您可以很好地对这些关键字使用宏。
  3. 如果不是 Qt,那么您希望依赖什么其他工具包来实现事件机制?在我看来,使用重叠的工具包进行开发是没有意义的,除非您希望保留依赖于 Qt 的可以配置的特定功能(在构建设置中的编译时)。在这种情况下,您最好使用工具链中的语义(automake、cmake,无论您使用什么)。
  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).
土豪 2024-10-26 05:15:22

你也可以反过来做。

如果不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文