Mainwindow.obj在编译时找不到?

时间:2015-07-29 08:11:43

标签: qt qprinter

我想从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但似乎没什么用。

mainwindow.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();

}

.pro文件:

#-------------------------------------------------
#
# 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

1 个答案:

答案 0 :(得分:2)

need to add QT += printsupport.pro文件。