使用该行使用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)
和铿锵(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中的definend)。
如果您使用新功能将qt源更新为某些内容而不再次运行configure,则会发生这种情况。运行configure时,将设置新功能。
这在Qt 5.12.3中得到修复。较新版本的notepad.cpp开始:
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printer)
#if QT_CONFIG(printdialog)
#include <QPrintDialog>
#endif // QT_CONFIG(printdialog)
#include <QPrinter>
#endif // QT_CONFIG(printer)
#endif // QT_PRINTSUPPORT_LIB
#include <QFont>
#include <QFontDialog>