Tanay Singh Sisodia
Tanay Singh Sisodia

Reputation: 21

Mainwindow.obj not found on compiling?

I want to print a pdf file from html but on compiling I get linker errors

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)

It happened in an earlier project so I looked for solutions where many people suggested making a new project and copying the code so I took only the problem code to the new project but it is still giving errors.I have already tried Clean & QMake but nothing seems to work.

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 file:

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

Upvotes: 0

Views: 1588

Answers (1)

cmannett85
cmannett85

Reputation: 22376

You need to add QT += printsupport to the .pro file.

Upvotes: 2

Related Questions