gpt4 book ai didi

c++ - 我应该尽可能使用#ifndef Q_MOC_RUN吗?

转载 作者:行者123 更新时间:2023-12-02 10:04:44 25 4
gpt4 key购买 nike

我有一个使用Boost库的Qt / C++项目,并且看到Boost header 包含如下内容:

#ifndef Q_MOC_RUN
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#endif

我读到,如果您不这样做,MOC可能会引起问题。

问题是,我不应该再使用此防护措施来包含所有其他绝对不包含Q_OBJECT marco的 header 吗?例如,标准库头文件和其他非Qt库? MOC预处理程序运行时,它不会节省很多时间吗?

最佳答案

在主题Qt5 moc error in combination with boost中:

First, this is a known MOC issue. The MOC can't expand some of the macros used in the Boost library. I believe the reason Qt 4.8 works is that a workaround for specific Boost macro definitions was added to the MOC configuration for that version.

What you need to do to work around this issue: As stated above, use Q_MOC_RUN to comment out problematic headers. You ONLY need to use Q_MOC_RUN in files that produce a moc file (e.g. myheader.h will produce moc_myheader.cpp). You can limit the hack to just those files. So you don't need to #ifndef all usages of Boost headers in your project which limits the pain of implementing this solution quite a bit.



似乎这个问题已经解决了很久了,所以无论您是否有任何问题并且不需要支持旧版本的Qt,您都不会在以后的代码中添加此宏。

关于c++ - 我应该尽可能使用#ifndef Q_MOC_RUN吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60837169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com