当前位置: 移动技术网 > IT编程>开发语言>C/C++ > clion+vs编译器+Qt5中使用QPrinter和QprintDialog类

clion+vs编译器+Qt5中使用QPrinter和QprintDialog类

2020年07月29日  | 移动技术网IT编程  | 我要评论

学习Qt过程中,实现用一个编辑器,其中需要使用到打印文本功能,在使用Qt printer时遇到了几个麻烦。

1.在使用到QPrinter和QprintDialog类时的附加处理

①若是在qt creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport”,否则会编译报错

②若是在VS编译器环境下,只需在相应头文件中添加以下两条语句
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>

2.在VS环境下,可能会出现如下报错:

mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl QPrinter::QPrinter(enum QPrinter::PrinterMode)" (__imp_??0QPrinter@@QEAA@W4PrinterMode@0@@Z),该符号在函数 "private: void __cdecl MainWindow::CreatPdf(void)" (?CreatPdf@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __cdecl QPrinter::~QPrinter(void)" (__imp_??1QPrinter@@UEAA@XZ),该符号在函数 "private: void __cdecl MainWindow::CreatPdf(void)" (?CreatPdf@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl QPrinter::setOutputFormat(enum QPrinter::OutputFormat)" (__imp_?setOutputFormat@QPrinter@@QEAAXW4OutputFormat@1@@Z),该符号在函数 "private: void __cdecl MainWindow::CreatPdf(void)" (?CreatPdf@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl QPrinter::setOutputFileName(class QString const &)" (__imp_?setOutputFileName@QPrinter@@QEAAXAEBVQString@@@Z),该符号在函数 "private: void __cdecl MainWindow::CreatPdf(void)" (?CreatPdf@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual void __cdecl QPrinter::setPageSize(enum QPagedPaintDevice::PageSize)" (__imp_?setPageSize@QPrinter@@UEAAXW4PageSize@QPagedPaintDevice@@@Z),该符号在函数 "private: void __cdecl MainWindow::CreatPdf(void)" (?CreatPdf@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl QPrintPreviewDialog::QPrintPreviewDialog(class QPrinter *,class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QPrintPreviewDialog@@QEAA@PEAVQPrinter@@PEAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z),该符号在函数 "private: void __cdecl MainWindow::PrintPreview(void)" (?PrintPreview@MainWindow@@AEAAXXZ) 中被引用
mainwindow.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __cdecl QPrintPreviewDialog::~QPrintPreviewDialog(void)" (__imp_??1QPrintPreviewDialog@@UEAA@XZ),该符号在函数 "private: void __cdecl MainWindow::PrintPreview(void)" (?PrintPreview@MainWindow@@AEAAXXZ) 中被引用
Qprint.exe : fatal error LNK1120: 7 个无法解析的外部命令

在这里插入图片描述
错误2019,一般都是由于缺少相应的库文件。从而导致无法解析外部符号

解决办法

配置cmakelist.txt文件,添加库文件“Qt5PrintSupport.lib”即可

具体方法:
在cmakelist.txt文件添加一行

target_link_libraries(Qprint Qt5::PrintSupport)

配置好的cmakelist文件如下:
在这里插入图片描述

本文地址:https://blog.csdn.net/qq_41827817/article/details/107610043

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网