3

使用该行使用 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。任何建议(错误用法?)表示赞赏。

4

3 回答 3

2

如果您使用新功能将您的 qt 源更新为某些内容而没有再次运行配置,则会发生这种情况。当您运行 configure 时,会设置新功能。

于 2019-04-24T12:51:18.313 回答
2

这在 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>
于 2019-06-14T20:27:48.790 回答
2

我认为你不应该专注于那个宏。该宏的目的是在 QT_FEATURE_printer 为零时简单地使您的编译代码崩溃。该代码并非旨在以其他方式工作。

与其有条件地使用宏,不如尝试找出 QT_FEATURE_printer 为零的原因并包含/配置依赖项来改变它(它似乎在 printsupport/qtprintsupport-config.h 中定义)。

于 2019-04-24T08:35:08.900 回答