Search code examples
qtqt6qgraphicssvgitem

QGraphicsSvgItem: No such file or directory


I wanted to create an aircraft altitude indicator and embed it in PyQt5.

I found a GitHub repository that has custom Altitude indicator built using cpp. Below is the link to the github repo.

https://github.com/marek-cel/QFlightinstruments

There is a video tutorial included at the end. I followed the exact steps he followed. But when I ran it, I got the following error.

"In file included from ..\Instruments\qfi\qfi_AI.cpp:23:

../Instruments/qfi/qfi_AI.h:28:10:fatal error: QGraphicsSvgItem: No such file or directory"

The same error is showing for qfi_EADI.h, qfi_EHSI.h and qfi_HI.h as well.

I have included the header files and added the following line to my .pro file

QT  += core gui svg

Below is my qfi_AI.h file (the .h and cpp file can be found in github)

#ifndef QFI_AI_H
#define QFI_AI_H

////////////////////////////////////////////////////////////////////////////////

#include <QGraphicsView>
#include <QGraphicsSvgItem>  //error

////////////////////////////////////////////////////////////////////////////////

/**
 * @brief Attitude Indicator widget class.
 */
class qfi_AI : public QGraphicsView
{
    Q_OBJECT

public:

    /** Constructor. */
    explicit qfi_AI( QWidget *parent = Q_NULLPTR );

    /** Destructor. */
    virtual ~qfi_AI();

    /** Reinitiates widget. */
    void reinit();

    /** Refreshes (redraws) widget. */
    void redraw();

    /** @param roll angle [deg] */
    void setRoll( double roll );

    /** @param pitch angle [deg] */
    void setPitch( double pitch );

protected:

    /** */
    void resizeEvent( QResizeEvent *event );

private:

    QGraphicsScene *_scene;

    QGraphicsSvgItem *_itemBack;
    QGraphicsSvgItem *_itemFace;
    QGraphicsSvgItem *_itemRing;
    QGraphicsSvgItem *_itemCase;

    double _roll;
    double _pitch;

    double _faceDeltaX_new;
    double _faceDeltaX_old;
    double _faceDeltaY_new;
    double _faceDeltaY_old;

    double _scaleX;
    double _scaleY;

    const int _originalHeight;
    const int _originalWidth;

    const double _originalPixPerDeg;

    QPointF _originalAdiCtr;

    const int _backZ;
    const int _faceZ;
    const int _ringZ;
    const int _caseZ;

    void init();

    void reset();

    void updateView();
};

////////////////////////////////////////////////////////////////////////////////

#endif //QFI_AI_H

How do I resolve this issue?


Solution

  • In Qt6 many submodules have been restructured, for example the QGraphicsSvgItem and QSvgWidget classes were moved to a new submodule called svgwidgets so that the svg submodule no longer depends on the widgets submodule which improves memory in applications that do not need widgets.

    So the solution is to add:

    QT += svgwidgets
    

    That is clearly indicated in the docs:

    enter image description here