使用 g++(从用 qmake 生成的 Makefile)编译
#if !QT_CONFIG(printer)
// do something
#endif
在两个 g++ (7.3.0) 上都出现预处理器错误
test.cpp:25:6: error: division by zero in #if
#if !QT_CONFIG(printer)
和 clang (6.00)
test.cpp:25:6: error: division by zero in preprocessor expression
#if !QT_CONFIG(printer)
^~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:84:30: note: expanded from macro 'QT_CONFIG'
#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
~^~~~~~~~~~~~~~~~~~~~~
1 error generated.
clang++ 给出了更详细的输出。 printer
未启用,因此建议使用宏进行条件编译。 QT版本为5.9.5。任何建议(错误用法?)表示赞赏。
最佳答案
我认为您不应该专注于该宏。该宏的目的是在 QT_FEATURE_printer 为零时简单地使您的编译代码崩溃。该代码并非旨在以其他方式工作。
不要有条件地使用宏,而是尝试找出 QT_FEATURE_printer 为零的原因并包含/配置依赖项以更改它(它似乎在 printsupport/qtprintsupport-config.h 中定义)。
关于c++ - 预处理器在评估 `QT_CONFIG(printer)` 时除以零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55823977/