Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSvgGenerator undefined reference error - SOLVED
Forum Update on Monday, May 27th 2025

QSvgGenerator undefined reference error - SOLVED

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zakkeri
    wrote on last edited by
    #1

    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>
    #include<QPushButton>
    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    private slots:
    void handleButton();

    private:
    Ui::Widget *ui;
    QPushButton *button;
    };

    #endif // WIDGET_H
    @

    Code for widget.cpp
    @#include "widget.h"
    #include "ui_widget.h"
    //#include <QCoreApplication>
    //#include<QObject>
    #include<QDebug>
    #include<QtSvg/QSvgGenerator>
    #include<QPainter>

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

    Widget::~Widget()
    {
    QObject::disconnect(button, SIGNAL(released()), this, SLOT(handleButton()));
    delete ui;
    }

    void Widget::handleButton()
    {

    qDebug()<<"Button pressed";
    QSvgGenerator generator;   //The errors start from here
    generator.setFileName("C:/Den/Research/DNA_Group/2svgFile.svg");
    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.begin(&generator);
    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));
    
    
    painter.end();
    

    }
    @

    main.cpp

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

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

    return a.exec(&#41;;
    

    }
    @

    Any suggestions?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

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

      @QT += svg@

      in your pro file.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zakkeri
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zakkeri
            wrote on last edited by
            #5

            Thank you, again! :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved