0

我想从 html 打印一个 pdf 文件,但在编译时出现链接器错误

tendersorter.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QPrinter::QPrinter(enum QPrinter::PrinterMode)" (__imp_??0QPrinter@@QEAA@W4PrinterMode@0@@Z) referenced in function "private: void __cdecl Tendersorter::on_pushButton_clicked(void)" (?on_pushButton_clicked@Tendersorter@@AEAAXXZ)

tendersorter.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QPrinter::setOutputFormat(enum QPrinter::OutputFormat)" (__imp_?setOutputFormat@QPrinter@@QEAAXW4OutputFormat@1@@Z) referenced in function "private: void __cdecl Tendersorter::on_pushButton_clicked(void)" (?on_pushButton_clicked@Tendersorter@@AEAAXXZ)

tendersorter.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QPrinter::setOutputFileName(class QString const &)" (__imp_?setOutputFileName@QPrinter@@QEAAXAEBVQString@@@Z) referenced in function "private: void __cdecl Tendersorter::on_pushButton_clicked(void)" (?on_pushButton_clicked@Tendersorter@@AEAAXXZ)

tendersorter.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual bool __cdecl QPrinter::newPage(void)" (__imp_?newPage@QPrinter@@UEAA_NXZ) referenced in function "private: void __cdecl Tendersorter::on_pushButton_clicked(void)" (?on_pushButton_clicked@Tendersorter@@AEAAXXZ)

tendersorter.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QPrinter::~QPrinter(void)" (__imp_??1QPrinter@@UEAA@XZ) referenced in function "private: void __cdecl Tendersorter::on_pushButton_clicked(void)" (?on_pushButton_clicked@Tendersorter@@AEAAXXZ)

它发生在一个较早的项目中,所以我寻找了许多人建议创建一个新项目并复制代码的解决方案,所以我只将问题代码带到了新项目中,但它仍然给出错误。我已经尝试过 Clean & QMake 但没有似乎工作。

主窗口.cpp

     #include "tendersorter.h"
        #include "ui_tendersorter.h"
        #include <QTextDocument>
        #include<QtPrintSupport/QPrinter>
        #include<QPainter>

        Tendersorter::Tendersorter(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Tendersorter)
{
    ui->setupUi(this);
}

Tendersorter::~Tendersorter()
{
    delete ui;
}

void Tendersorter::on_pushButton_clicked()
{
    QTextDocument doc;
     doc.setHtml( "<p>A QTextDocument can be used to present formatted text "
                  "in a nice way.</p>"
                  "<p align=center>It can be <b>formatted</b> "
                  "<font size=+2>in</font> <i>different</i> ways.</p>"
                  "<p>The text can be really long and contain many "
                  "paragraphs. It is properly wrapped and such...</p>" );
      QPrinter printer;
      printer.setOutputFileName("C:/Users/ASUS-PC/Desktop/test.pdf");
      printer.setOutputFormat(QPrinter::PdfFormat);
      doc.print(&printer);
      printer.newPage();

}

。轮廓:

#-------------------------------------------------
#
# Project created by QtCreator 2015-02-25T19:59:51
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = TendersSorter
TEMPLATE = app


SOURCES += main.cpp\
        tendersorter.cpp

HEADERS  += tendersorter.h

FORMS    += tendersorter.ui
4

1 回答 1

2

需要添加 QT += printsupport.pro文件中。

于 2015-07-29T08:37:05.187 回答