Qt5中使用QPrinter和QprintDialog类

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


一、在使用到QPrinter和QprintDialog类时的附加处理

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

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


二、在VS环境下,可能会出现如下报错:

error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QPrintDialog::QPrintDialog(class QPrinter *,class QWidget *)" (__imp_??0QPrintDialog@@QAE@PAVQPrinter@@PAVQWidget@@@Z),该符号在函数 "protected: void __thiscall EasyEditor::showPrintText(void)" (?showPrintText@EasyEditor@@IAEXXZ) 中被引用 F:\QtSourceCode\Easy Editor\Easy Editor\EasyEditor.objEasy Editor


错误2019,一般都是由于缺少相应的库文件。

解决办法:

右击项目,选择“属性”-->“链接器”-->“输入”-->"附加依赖项"-->"编辑"

在最后添加上“Qt5PrintSupport.lib”即可。


写此以记之,如有不对,欢迎指出。


猜你喜欢

转载自blog.csdn.net/qq_37174526/article/details/79132051
今日推荐