c/c++语言开发共享clion+vs编译器+Qt5中使用QPrinter和QprintDialog类

学习Qt过程中,实现用一个编辑器,其中需要使用到打印文本功能,在使用Qt printer时遇到了几个麻烦。1.在使用到QPrinter和QprintDialog类时的附加处理①若是在qt creator中,需要在 (.pro)工程文件中加入 “QT+= printsupport”,否则会编译报错②若是在VS编译器环境下,只需在相应头文件中添加以下两条语句#include <QtPrintSupport/QPrintDialog>#include <QtPrintSupport/Q

学习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 个无法解析的外部命令 

clion+vs编译器+Qt5中使用QPrinter和QprintDialog类
错误2019,一般都是由于缺少相应的库文件。从而导致无法解析外部符号

解决办法

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

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

target_link_libraries(Qprint Qt5::PrintSupport) 

配置好的cmakelist文件如下:
clion+vs编译器+Qt5中使用QPrinter和QprintDialog类

c/c++开发分享clion+vs编译器+Qt5中使用QPrinter和QprintDialog类地址:https://blog.csdn.net/qq_41827817/article/details/107610043

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/598378.html

(0)
上一篇 2021年5月8日
下一篇 2021年5月8日

精彩推荐