问题:Qt中包含QPrintDialog、QPrinter、QPrintPreviewDialog失败;在引入printsupport后报cpp:651: error: undefined reference to `_imp___ZN8QPrinterC1ENS_11PrinterModeE'错误的原因?
解决方法:
1. 在Qt中引入QPrintDialog、QPrinter、QPrintPreviewDialog头文件需要分别使用QtPrintSupport
#include<QtPrintSupport/QPrintDialog>
#include<QtPrintSupport/QPrinter>
#include<QtPrintSupport/QPrintPreviewDialog>
在引入QtPrintSupport后还会报下面
cpp:651: error: undefined reference to `_imp___ZN8QPrinterC1ENS_11PrinterModeE'这样的错误
此时还需要在工程的Pro文件中引入printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
此时问题就可以解决了。
2.另外一种方法是在工程的Pro文件中直接加配置
qtHaveModule(printsupport): QT += printsupport
案例:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
qtHaveModule(printsupport): QT += printsupport
TARGET = MyselfWord
TEMPLATE = app