Important: Please read the Qt Code of Conduct -

QSvgGenerator undefined reference error - SOLVED

  • I was trying to create an svg file using QSvgGenerator class, but during compilation I'm getting 9 errors that look something like:

    undefined reference to '_imp__ZN13QSvgGeneratorC1EV'

    The rest errors also says that there is an undefined reference to methods of QSvgGenerator

    Here is my code for widget.h
    @#ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>
    namespace Ui {
    class Widget;

    class Widget : public QWidget

    explicit Widget(QWidget *parent = 0);

    private slots:
    void handleButton();

    Ui::Widget *ui;
    QPushButton *button;

    #endif // WIDGET_H

    Code for widget.cpp
    @#include "widget.h"
    #include "ui_widget.h"
    //#include <QCoreApplication>

    Widget::Widget(QWidget *parent) :
    ui(new Ui::Widget)
    button = ui->pushButton;
    QObject::connect(button, SIGNAL(released()), this, SLOT(handleButton()));

    QObject::disconnect(button, SIGNAL(released()), this, SLOT(handleButton()));
    delete ui;

    void Widget::handleButton()

    qDebug()<<"Button pressed";
    QSvgGenerator generator;   //The errors start from here
    generator.setSize(QSize(200, 200));
    generator.setViewBox(QRect(0, 0, 200, 200));
    generator.setTitle(tr("SVG Generator Example Drawing"));
    generator.setDescription(tr("An SVG drawing created by the SVG Generator "
                                    "Example provided with Qt."));
    QPainter painter;
    painter.fillRect(QRect(0, 0, 200, 200), Qt::gray);
             painter.setPen(QPen(Qt::white, 4, Qt::DashLine));
             painter.drawLine(QLine(0, 35, 200, 35));
             painter.drawLine(QLine(0, 165, 200, 165));



    @#include "widget.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    Widget w;;

    return a.exec(&#41;;


    Any suggestions?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you are using the QtSvg module, you are missing:

    @QT += svg@

    in your pro file.

  • Thank you!!! Everything is working now!!

    Do you know where can I find more information about .pro files?
    So that I know what I should include in the future.

  • Lifetime Qt Champion

    The qmake documentation and the various Qt modules documentation (look for example at QtSvg in the doc)

    Don't forget to update the thread's title to solved so other forum users may know a solution has been found :)

  • Thank you, again! :)

Log in to reply